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 ...
随机推荐
- 系统中sshd进程的查看,数量统计,进程号输出,进程清理命令
1. 查看sshd进程 ps -ef|grep sshd ps -ef:打开所有的进程 grep sshd:过滤出含有“sshd”字符的进程. 2. 查看sshd进程中的sftp进程,不含查询的进程 ...
- eclipse自定义代码块折叠
1.下载插件 com.cb.eclipse.folding_1.0.6.jar 下载地址:http://files.cnblogs.com/haiq/代码折叠插件_com.cb.eclipse.fol ...
- PHP如何实现静态的链式调用
Db::table('**')->where('***','***')->order('***')->find('**'); 想这种应该怎么实现 public function ta ...
- 海思 Hi3516A Hi3518E V200 芯片介绍
海康是生产监控摄像头和硬盘录像机的,海思是提供机器里芯片的,海思属于华为的. http://www.hisilicon.com/en/Products/ProductList/Surveillance ...
- [原][bigemap][globalmapper]通过bigemap下载全球30米DEM高程数据(手动下载)(下载全球高精度dom卫片、影像、等高线、矢量路网、POI、行政边界)
本文研究了bigemap下载高程数据的方式,但是严重不推荐使用这总手动方式,bigemap这个软件一次只能下载100M以内的高程数据,即使花钱,也不给你提供批量下载dem的方式!也有些其他更好的软件, ...
- 为什么static成员必须在类外初始化,而不能在类的头文件中初始化
为什么static成员必须在类外初始化 为什么静态成员不能在类内初始化 在C++中,类的静态成员(static member)必须在类内声明,在类外初始化,像下面这样. class A { pri ...
- 004-行为型-03-观察者模式(Observer)
一.概述 当对象间存在一对多关系时,则使用观察者模式(Observer Pattern).比如,当一个对象被修改时,则会自动通知它的依赖对象. 定义了对象之间的一对多依赖,让多个观察者对象同时监听某一 ...
- Spring cloud微服务安全实战-5-12实现基于token的SSO(2)
我只要把这个meFilter放在AuthorizationFilter后面就可以了. authorizationFilter的排序是3 MeFilter设置为4 就可以了. 拿到了username直接 ...
- Spring cloud微服务安全实战-4-3常见的微服务安全整体架构
整体架构 这个图适合中小公司.麻雀虽小 五脏俱全.微服务架构所需要做的事在这个图里基本都有了. 绿色的不讲,主要讲的是这三块(橘黄色的).后面的和运维相关,会讲,不会讲的太深 订单服务 首先来写一个订 ...
- 增强篇3 SAP表字段增强
有两种方式: Include 和 Append 1.INCLUDE一般都是标准预留的增强: 以CO01生产订单增强字段为例 在表AUFK中INCLUDE的结构“CI_AUFK”加入自定义字段 保存 ...