Educational Codeforces Round 23 A-F 补题
注意负数和0的特殊处理。。 水题。。 然而又被Hack了 吗的智障
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int sa,sb,da,db,x,y;
- scanf("%d%d%d%d%d%d",&sa,&sb,&da,&db,&x,&y);
- sa=da-sa;sb=db-sb;
- if(sa<0)sa*=-1;
- if(sb<0)sb*=-1;
- if(x<0)x*=-1;
- if(y<0)y*=-1;
- if((sa!=0&&x==0)||(sb!=0&&y==0)){printf("NO\n");return 0;}
- if((sa==0)&&(sb==0)){printf("YES\n");return 0;}
- if(((sa%x)!=0)||((sb%y)!=0)){printf("NO\n");return 0;}
- if((((max(sa/x,sb/y))-(min(sa/x,sb/y)))%2)!=0){printf("NO\n");return 0;}
- printf("YES\n");
- return 0;
- }
排序后求一下组合数就好了。。
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int LL;
- const int N=2e5;
- LL num[N];
- map<LL,LL>ma;
- LL C(LL n,LL m)
- {
- LL ans=1;
- for(int i=0;i<m;i++)
- ans*=n-i;
- for(int i=m;i>=2;i--)
- ans/=i;
- return ans;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- for(int i=0;i<n;i++)scanf("%I64d",num+i);
- sort(num,num+n);
- LL ans=1;
- for(int i=0;i<3;i++)
- ma[num[i]]++;
- LL l=ma[num[2]];
- for(int i=3;i<n&&num[i]==num[2];i++)
- {
- l++;
- }
- ans=ans*C(l,ma[num[2]]);
- printf("%I64d\n",ans);
- return 0;
- }
肯定存在某个数k 大于k的数都是big number... 二分找最小的k就好了
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int LL;
- LL sum(LL x)
- {
- LL dex=1;
- LL ans=0;
- while(x>0)
- {
- ans+=((x%10)*(dex-1));
- x/=10;dex*=10;
- }
- return ans;
- }
- int main()
- {
- LL n,s;
- scanf("%I64d%I64d",&n,&s);
- LL l=1,r=n;
- LL i;
- bool flag=false;
- LL ri;
- while(l<=r&&r<=n)
- {
- i=(l+r)>>1;
- if(sum(i)>=s){flag=true;ri=i;r=i-1;}
- else {l=i+1;}
- }
- if(flag) {printf("%I64d\n",(n-ri+1));return 0;}
- else printf("0\n");
- return 0;
- }
暴力枚举每个区间 复杂度O(n^2)起步 显然是不可以的。
那么只能考虑每个位置对答案做的贡献。即它是多少个区间的最值?
用栈维护,从前往后一个一个堆栈,并且保证栈中的所有元素构成不上升序列即可。
复杂度O(n)技巧性还是很强的。。
- #include <bits/stdc++.h>
- using namespace std;
- long long n,pos[1000005],neg[1000005];
- long long solve(long long a[]){
- stack<pair<int,long long>> s;
- a[n]=1e8;
- s.push({-1,1e9});
- long long sum=0;
- for(int i=0;i<=n;s.push({i,a[i]}),++i)
- while(a[i]>=s.top().second){
- auto p=s.top();
- s.pop();
- auto p2=s.top();
- sum+=p.second*(i-p.first)*(p.first-p2.first);
- }
- return sum;
- }
- int main(){
- ios_base::sync_with_stdio(0);
- cin>>n;
- for(int i=0;i<n;neg[i]=(-1)*pos[i],++i)
- cin>>pos[i];
- cout<<solve(pos)+solve(neg);
- }
很有趣的一道数据结构题
我们考虑 xor运算是按位进行的
比较大小也可以按位进行
那么 如果我们同样按位储存所有的士兵性格可以么?
是的,用一颗Trie来储存所有的士兵 就可以在logn的时间内完成一个访问了!
- #include<bits/stdc++.h>
- #define N 3000005
- using namespace std;
- int size[N],ch[N][2],n,cnt,a,b,type;
- inline void ins(int x,int add){
- int now=1;
- for(int i=26;i>=0;i--){
- bool v=((x>>i)&1);
- if(!ch[now][v])ch[now][v]=++cnt;
- now=ch[now][v];
- size[now]+=add;
- }
- }
- inline void query(int x,int y){
- int ans=0,now=1,val=0;
- for(int i=26;i>=0&&now;i--){
- bool xbit=((x>>i)&1),ybit=((y>>i)&1);
- val+=val;
- if(ybit){
- ans+=size[ch[now][xbit]];now=ch[now][!xbit];
- val+=!xbit;
- }
- else{now=ch[now][xbit];val+=xbit;}
- }
- printf("%d\n",ans);
- }
- inline int read(){
- int f=1,x=0;char ch;
- do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
- do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
- return f*x;
- }
- int main(){
- cnt=1;n=read();
- while(n--){
- int opt=read(),x=read();
- if(opt==1)ins(x,1);
- if(opt==2)ins(x,-1);
- if(opt==3){
- int y=read();
- query(x,y);
- }
- }
- }
首先 这道题是离线询问的 也就是我们预知了所有询问。
那么,一个数字如果要成为答案,那么它必然是某个询问的边界值。
所以我们只要维护所有询问的边界值即可,总共有2*10^5个。
用线段树维护,每个命令要么删除某些数,要么增加某些数。
进行完一个命令后,取线段树上存在的且最靠左的值即可。(每个线段树节点保存当前区间存在的整数个数)
- #include<bits/stdc++.h>
- #define N 400005
- #define LL long long
- #define TAT "%I64d"
- #define L(__) (__ << 1)
- #define R(__) (L(__)|1)
- using namespace std;
- LL sz[4*N],L[N],R[N],w[N]; int q,op[N],tag[4*N],lw;
- void TS(int t,int d,int o)
- {
- if(o==1) tag[t]^=1,sz[t]=d-sz[t];
- if(o==2) tag[t]=o,sz[t]=d;
- if(o==3) tag[t]=o,sz[t]=0;
- }
- void push(int t,int d)
- {
- if(!tag[t]) return ;
- TS(L(t),(d+1)/2,tag[t]);
- TS(R(t),d/2,tag[t]);
- tag[t]=0;
- }
- void M(int t,int l,int r,int l1,int r1,int op)
- {
- int mid=(l+r)>>1;
- if(l>r1 || r<l1) return ;
- if(l>=l1&&r<=r1) return TS(t,r-l+1,op);
- push(t,r-l+1);
- M(L(t),l,mid,l1,r1,op);
- M(R(t),mid+1,r,l1,r1,op);
- sz[t]=sz[L(t)]+sz[R(t)];
- }
- int Q(int t,int l,int r)
- {
- int mid=(l+r)>>1,x;
- if(l==r) return l;
- push(t,r-l+1);
- if(sz[L(t)]==(r-l)/2+1)
- x=Q(R(t),mid+1,r);
- else x=Q(L(t),l,mid);
- sz[t]=sz[L(t)]+sz[R(t)];
- return x;
- }
- int main()
- {
- int i;
- scanf("%d",&q),w[lw=1]=1;
- for(i=1;i<=q;i++){
- scanf("%d"TAT""TAT,&op[i],&L[i],&R[i]);
- w[++lw]=L[i],w[++lw]=L[i]+1;
- w[++lw]=R[i],w[++lw]=R[i]+1;
- }
- sort(w+1,w+lw+1);
- lw=unique(w+1,w+lw+1)-w-1;
- for(i=1;i<=q;i++){
- L[i]=lower_bound(w+1,w+lw+1,L[i])-w;
- R[i]=lower_bound(w+1,w+lw+1,R[i])-w;
- M(1,1,lw,L[i],R[i],op[i]%3+1);
- printf(TAT"\n",w[Q(1,1,lw)]);
- }
- return 0;
- }
Educational Codeforces Round 23 A-F 补题的更多相关文章
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Educational Codeforces Round 23 补题小结
昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...
- Educational Codeforces Round 23 F. MEX Queries 离散化+线段树
F. MEX Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- codeforces Educational Codeforces Round 24 (A~F)
题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...
- Codeforces Round #585 (Div. 2) [补题]
前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...
- Codeforces Round #429 (Div. 2) 补题
A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...
- Codeforces Round #419 (Div. 1) 补题 CF 815 A-E
A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. ...
- Codeforces Round #590 (Div. 3)补题
要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ∅ √ 解 E 待定 F 传送门 第一 ...
- Educational Codeforces Round 65 E,F
E. Range Deleting 题意:给出一个序列,定义一个操作f(x,y)为删除序列中所有在[x,y]区间内的数.问能使剩下的数单调不减的操作f(x,y)的方案数是多少. 解法:不会做,思维跟不 ...
随机推荐
- [codevs1050]棋盘染色 2
[codevs1050]棋盘染色 2 试题描述 有一个5*N的棋盘,棋盘中的一些格子已经被染成了黑色,你的任务是对最少的格子染色,使得所有的黑色能连成一块. 输入 第一行一个整数N(<=100) ...
- HDU 6076 (动态规划)
HDU 6076 Security Check Problem : 有两个长度为n的队列过安检,每个人有一个特征值.如果两个队列中的第一个人的特征值之差小于等于k,那么一次只能检查其中一个人,否则一次 ...
- 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]
传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...
- Google SPDY
SPDY(读作“SPeeDY”)是Google开发的基于TCP的应用层协议,用以最小化网络延迟,提升网络速度,优化用户的网络使用体验.SPDY并不是一种用于替代HTTP的协议,而是对HTTP协议的增强 ...
- IDEA添加作者注释
1.打开IDEA的settings,然后在Editor下找到File and Code Templates 2.然后选择File Header 选择需要注释的的格式即可.
- CDI Services *Decoretions *Intercepters * Scope * EL\(Sp EL) *Eventmodel
1.Decorators装饰器综述 拦截器是一种强大的方法在应用程序捕捉运行方法和解耦.拦截器可以拦截任何java类型的调用. 这使得拦截器适合解决事务管理,安全性,以及日记记录. 本质上说,拦截 ...
- EF关联
public CustomerMap() { this.ToTable("Customer"); this.HasKey(c => c.Id); this.Property( ...
- spring-boot-starter-data-redis与spring-boot-starter-redis两个包的区别
spring-boot-starter-data-redis: <?xml version="1.0" encoding="UTF-8"?> < ...
- CSS3 水波纹
css3 动画设置水波纹,效果如下图: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- Java实现敏感词过滤代码
原文:http://www.open-open.com/code/view/1445762764148 import java.io.BufferedReader; import java.io.Fi ...