Educational Codeforces Round 65 (Div. 2)
A.前n-10个有8即合法。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
char s[N];
int T,n; int main(){
for (scanf("%d",&T); T--; ){
scanf("%d%s",&n,s+); bool flag=;
rep(i,,n-+) if (s[i]==''){ flag=; break; }
if (flag) puts("YES"); else puts("NO");
}
return ;
}
B.这6个数两两乘积不同,于是有多种方法。
(1) (1,1) (2,2) (3,4) (3,5)
(2) (1,2) (3,4) (1,3) (1,5)
(3) (1,2) (2,3) (4,5) (5,6)
(方法三能做7个数的情况)
下面写的是方法一,因为判的情况没写全导致场上FST。
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int x,y,a[N],b[N]; bool ok(int i){ return i== || i== || i== || i== || i== || i==; } int main(){
puts("? 1 1"); fflush(stdout); scanf("%d",&a[]); a[]=sqrt(a[]);
puts("? 2 2"); fflush(stdout); scanf("%d",&a[]); a[]=sqrt(a[]);
puts("? 3 4"); fflush(stdout); scanf("%d",&x);
puts("? 3 5"); fflush(stdout); scanf("%d",&y);
rep(i,,) if (ok(i) && (x%i==) && (y%i==) && ok(x/i) && ok(y/i)){
rep(j,,) b[j]=;
b[a[]]++; b[a[]]++; b[i]++; b[x/i]++; b[y/i]++; b[+++++-a[]-a[]-i-x/i-y/i]++;
bool flag=;
rep(j,,) if (ok(j) && b[j]!=){ flag=; break; }
if (flag) continue;
printf("! %d %d %d %d %d %d\n",a[],a[],i,x/i,y/i,+++++-a[]-a[]-i-x/i-y/i); break;
}
return ;
}
C.并查集
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,m,k,fa[N],sz[N],a[N]; int get(int x){ return fa[x]==x ? x : fa[x]=get(fa[x]); } int main(){
scanf("%d%d",&n,&m);
rep(i,,n) fa[i]=i,sz[i]=;
rep(i,,m){
scanf("%d",&k);
rep(j,,k) scanf("%d",&a[j]);
rep(j,,k-) if (get(a[j])!=get(a[j+])) sz[get(a[j+])]+=sz[get(a[j])],fa[get(a[j])]=get(a[j+]);
}
rep(i,,n) printf("%d ",sz[get(i)]);
return ;
}
D.贪心
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=;
int n,x,y,mx,b[N];
char s[N]; int main(){
scanf("%d%s",&n,s+);
rep(i,,n){
if (s[i]=='('){ if (x<=y) x++,b[i]=; else y++,b[i]=; }
else{ if (x<=y) y--,b[i]=; else x--,b[i]=; }
}
rep(i,,n) printf("%d",b[i]);
return ;
}
E.找到最大的l是的[1,l]的所有数加入序列后都是有序的,同样找到最小的r满足[r,m]的所有数都相对有序,然后two-pointers统计答案即可,细节很多比较难写。
F.对每个数a[i]求它的贡献,也即它在所有包含它的区间中的排名之和。从小到大加数,考虑每个已加的数在多少个区间中对它产生1的贡献,树状数组直接维护即可。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std; const int N=,mod=1e9+;
int n,m,i,j,a[N],id[N],c1[N],c2[N],ans; bool cmp(int x,int y){ return a[x]<a[y]; }
void inc(int&x,int v){ x+=v; if(x>=mod)x-=mod; }
void add(int c[N],int x,int v){ while (x<=n) inc(c[x],v),x+=x&-x; }
int que(int c[N],int x,int res=){ while (x) inc(res,c[x]),x-=x&-x; return res; } int main(){
scanf("%d",&n);
rep(i,,n) scanf("%d",&a[i]),id[i]=i;
sort(id+,id+n+,cmp);
rep(i,,n){
add(c1,id[i],id[i]);
ans=(ans+1ll*a[id[i]]*(1ll*(n-id[i]+)*que(c1,id[i])%mod+1ll*id[i]*que(c2,n-id[i]+)%mod)%mod)%mod;
add(c2,n-id[i]+,n-id[i]+);
}
printf("%d\n",ans);
return ;
}
Educational Codeforces Round 65 (Div. 2)的更多相关文章
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 84 (Div. 2)
Educational Codeforces Round 84 (Div. 2) 读题读题读题+脑筋急转弯 = =. A. Sum of Odd Integers 奇奇为奇,奇偶为偶,所以n,k奇偶性 ...
- Educational Codeforces Round 65 (Rated for Div. 2) D. Bicolored RBS
链接:https://codeforces.com/contest/1167/problem/D 题意: A string is called bracket sequence if it does ...
- Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution
链接:https://codeforces.com/contest/1167/problem/C 题意: In some social network, there are nn users comm ...
- Educational Codeforces Round 65 (Rated for Div. 2) B. Lost Numbers
链接:https://codeforces.com/contest/1167/problem/B 题意: This is an interactive problem. Remember to flu ...
- Educational Codeforces Round 65 (Rated for Div. 2) A. Telephone Number
链接:https://codeforces.com/contest/1167/problem/A 题意: A telephone number is a sequence of exactly 11 ...
- Educational Codeforces Round 65 (Rated for Div. 2)B. Lost Numbers(交互)
This is an interactive problem. Remember to flush your output while communicating with the testing p ...
- [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]
https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory li ...
- Educational Codeforces Round 65 (Rated for Div. 2)
A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...
随机推荐
- j2s7s300 refers to jaco v2 7DOF spherical 3fingers
<?xml version="1.0"?> <!-- j2s7s300 refers to jaco v2 7DOF spherical 3fingers --& ...
- linux安装qt
1.下载run文件 2../运行 3.修改配置文件 sudo gedit /etc/profile 添加如下: port QTDIR=/home/rainbow/zhuxy/soft/Qt5.9.0/ ...
- 123457123457#0#-----com.tym.PuzzleGame28--前拼后广--日常pt-tym
com.tym.PuzzleGame28--前拼后广--日常pt-tym
- SegNet
Paper link:https://arxiv.org/pdf/1511.00561.pdf Motivation:为了实际应用,主要是在时间效率和存储空间上做了改进: Introduction: ...
- OpenGL程序无法启动此应用程序,因为计算机中丢失glut32.dll(转))
今天打开一个OpenGL源码,各种修改之后想要运行看一下效果,结果在我的开发环境下出现缺少相应的dll库: Windows7 64位+VS2010 提示:程序无法启动此应用程序,因为计算机中丢失glu ...
- 【docker 镜像源】解决quay.io和gcr.io国内无法访问的问题
该问题容易导致image pull back off 错误,应当换源: 微软: https://yeasy.gitbooks.io/docker_practice/install/mirror.htm ...
- jquery创建一个新的节点对象(自定义结构/内容)的好方法
jq创建一个新的节点对象,这对一些自定义功能很有帮助,而且可以随意控制对象的结构与内容,何乐而不为呢,看到这里,相信有些朋友已经按耐不住了,好记下来为大家介绍实现方法,感兴趣的朋友可以了解下哦 < ...
- react 生命周期图解
参考地址:https://www.cnblogs.com/gdsblog/p/7348375.html
- 单元测试-测试技术(Unit Test)
1.1白盒测试和单元测试的区别的论述: 1) 单元测试和白盒测试是不同的,虽然单元测试和白盒测试都是关注功能,虽然他们都需要代码支持,但是级别不同, 白盒测试关注的是类中一个方法的功能是更小的单位,但 ...
- 【C/C++开发】值得学习的C语言开源项目
值得学习的C语言开源项目 - 1. Webbench Webbench是一个在Linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的 ...