Treasure Hunt

注意负数和0的特殊处理。。 水题。。 然而又被Hack了 吗的智障

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int sa,sb,da,db,x,y;
  7. scanf("%d%d%d%d%d%d",&sa,&sb,&da,&db,&x,&y);
  8. sa=da-sa;sb=db-sb;
  9. if(sa<0)sa*=-1;
  10. if(sb<0)sb*=-1;
  11. if(x<0)x*=-1;
  12. if(y<0)y*=-1;
  13. if((sa!=0&&x==0)||(sb!=0&&y==0)){printf("NO\n");return 0;}
  14. if((sa==0)&&(sb==0)){printf("YES\n");return 0;}
  15. if(((sa%x)!=0)||((sb%y)!=0)){printf("NO\n");return 0;}
  16. if((((max(sa/x,sb/y))-(min(sa/x,sb/y)))%2)!=0){printf("NO\n");return 0;}
  17. printf("YES\n");
  18. return 0;
  19. }

Makes And The Product

排序后求一下组合数就好了。。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int LL;
  4. const int N=2e5;
  5. LL num[N];
  6. map<LL,LL>ma;
  7.  
  8. LL C(LL n,LL m)
  9. {
  10. LL ans=1;
  11. for(int i=0;i<m;i++)
  12. ans*=n-i;
  13. for(int i=m;i>=2;i--)
  14. ans/=i;
  15. return ans;
  16. }
  17. int main()
  18. {
  19. int n;
  20. scanf("%d",&n);
  21. for(int i=0;i<n;i++)scanf("%I64d",num+i);
  22. sort(num,num+n);
  23. LL ans=1;
  24. for(int i=0;i<3;i++)
  25. ma[num[i]]++;
  26. LL l=ma[num[2]];
  27. for(int i=3;i<n&&num[i]==num[2];i++)
  28. {
  29. l++;
  30. }
  31. ans=ans*C(l,ma[num[2]]);
  32. printf("%I64d\n",ans);
  33. return 0;
  34. }

Really Big Numbers

肯定存在某个数k 大于k的数都是big number... 二分找最小的k就好了

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int LL;
  4.  
  5. LL sum(LL x)
  6. {
  7. LL dex=1;
  8. LL ans=0;
  9. while(x>0)
  10. {
  11. ans+=((x%10)*(dex-1));
  12. x/=10;dex*=10;
  13. }
  14. return ans;
  15. }
  16.  
  17. int main()
  18. {
  19. LL n,s;
  20. scanf("%I64d%I64d",&n,&s);
  21. LL l=1,r=n;
  22. LL i;
  23. bool flag=false;
  24. LL ri;
  25. while(l<=r&&r<=n)
  26. {
  27. i=(l+r)>>1;
  28. if(sum(i)>=s){flag=true;ri=i;r=i-1;}
  29. else {l=i+1;}
  30. }
  31. if(flag) {printf("%I64d\n",(n-ri+1));return 0;}
  32. else printf("0\n");
  33. return 0;
  34. }

Imbalanced Array

暴力枚举每个区间 复杂度O(n^2)起步 显然是不可以的。

那么只能考虑每个位置对答案做的贡献。即它是多少个区间的最值?

用栈维护,从前往后一个一个堆栈,并且保证栈中的所有元素构成不上升序列即可。

复杂度O(n)技巧性还是很强的。。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long n,pos[1000005],neg[1000005];
  4. long long solve(long long a[]){
  5. stack<pair<int,long long>> s;
  6. a[n]=1e8;
  7. s.push({-1,1e9});
  8. long long sum=0;
  9. for(int i=0;i<=n;s.push({i,a[i]}),++i)
  10. while(a[i]>=s.top().second){
  11. auto p=s.top();
  12. s.pop();
  13. auto p2=s.top();
  14. sum+=p.second*(i-p.first)*(p.first-p2.first);
  15. }
  16. return sum;
  17. }
  18. int main(){
  19. ios_base::sync_with_stdio(0);
  20. cin>>n;
  21. for(int i=0;i<n;neg[i]=(-1)*pos[i],++i)
  22. cin>>pos[i];
  23. cout<<solve(pos)+solve(neg);
  24. }

  

Choosing The Commander

很有趣的一道数据结构题

我们考虑 xor运算是按位进行的

    比较大小也可以按位进行

那么 如果我们同样按位储存所有的士兵性格可以么?

是的,用一颗Trie来储存所有的士兵 就可以在logn的时间内完成一个访问了!

  1. #include<bits/stdc++.h>
  2. #define N 3000005
  3. using namespace std;
  4. int size[N],ch[N][2],n,cnt,a,b,type;
  5. inline void ins(int x,int add){
  6. int now=1;
  7. for(int i=26;i>=0;i--){
  8. bool v=((x>>i)&1);
  9. if(!ch[now][v])ch[now][v]=++cnt;
  10. now=ch[now][v];
  11. size[now]+=add;
  12. }
  13. }
  14. inline void query(int x,int y){
  15. int ans=0,now=1,val=0;
  16. for(int i=26;i>=0&&now;i--){
  17. bool xbit=((x>>i)&1),ybit=((y>>i)&1);
  18. val+=val;
  19. if(ybit){
  20. ans+=size[ch[now][xbit]];now=ch[now][!xbit];
  21. val+=!xbit;
  22. }
  23. else{now=ch[now][xbit];val+=xbit;}
  24. }
  25. printf("%d\n",ans);
  26. }
  27. inline int read(){
  28. int f=1,x=0;char ch;
  29. do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
  30. do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
  31. return f*x;
  32. }
  33. int main(){
  34. cnt=1;n=read();
  35. while(n--){
  36. int opt=read(),x=read();
  37. if(opt==1)ins(x,1);
  38. if(opt==2)ins(x,-1);
  39. if(opt==3){
  40. int y=read();
  41. query(x,y);
  42. }
  43. }
  44. }

  

MEX Queries

首先 这道题是离线询问的 也就是我们预知了所有询问。

那么,一个数字如果要成为答案,那么它必然是某个询问的边界值。

所以我们只要维护所有询问的边界值即可,总共有2*10^5个。

用线段树维护,每个命令要么删除某些数,要么增加某些数。

进行完一个命令后,取线段树上存在的且最靠左的值即可。(每个线段树节点保存当前区间存在的整数个数)

  1. #include<bits/stdc++.h>
  2. #define N 400005
  3. #define LL long long
  4. #define TAT "%I64d"
  5. #define L(__) (__ << 1)
  6. #define R(__) (L(__)|1)
  7. using namespace std;
  8. LL sz[4*N],L[N],R[N],w[N]; int q,op[N],tag[4*N],lw;
  9. void TS(int t,int d,int o)
  10. {
  11. if(o==1) tag[t]^=1,sz[t]=d-sz[t];
  12. if(o==2) tag[t]=o,sz[t]=d;
  13. if(o==3) tag[t]=o,sz[t]=0;
  14. }
  15. void push(int t,int d)
  16. {
  17. if(!tag[t]) return ;
  18. TS(L(t),(d+1)/2,tag[t]);
  19. TS(R(t),d/2,tag[t]);
  20. tag[t]=0;
  21. }
  22. void M(int t,int l,int r,int l1,int r1,int op)
  23. {
  24. int mid=(l+r)>>1;
  25. if(l>r1 || r<l1) return ;
  26. if(l>=l1&&r<=r1) return TS(t,r-l+1,op);
  27. push(t,r-l+1);
  28. M(L(t),l,mid,l1,r1,op);
  29. M(R(t),mid+1,r,l1,r1,op);
  30. sz[t]=sz[L(t)]+sz[R(t)];
  31. }
  32. int Q(int t,int l,int r)
  33. {
  34. int mid=(l+r)>>1,x;
  35. if(l==r) return l;
  36. push(t,r-l+1);
  37. if(sz[L(t)]==(r-l)/2+1)
  38. x=Q(R(t),mid+1,r);
  39. else x=Q(L(t),l,mid);
  40. sz[t]=sz[L(t)]+sz[R(t)];
  41. return x;
  42. }
  43. int main()
  44. {
  45. int i;
  46. scanf("%d",&q),w[lw=1]=1;
  47. for(i=1;i<=q;i++){
  48. scanf("%d"TAT""TAT,&op[i],&L[i],&R[i]);
  49. w[++lw]=L[i],w[++lw]=L[i]+1;
  50. w[++lw]=R[i],w[++lw]=R[i]+1;
  51. }
  52. sort(w+1,w+lw+1);
  53. lw=unique(w+1,w+lw+1)-w-1;
  54. for(i=1;i<=q;i++){
  55. L[i]=lower_bound(w+1,w+lw+1,L[i])-w;
  56. R[i]=lower_bound(w+1,w+lw+1,R[i])-w;
  57. M(1,1,lw,L[i],R[i],op[i]%3+1);
  58. printf(TAT"\n",w[Q(1,1,lw)]);
  59. }
  60. return 0;
  61. }

  

Educational Codeforces Round 23 A-F 补题的更多相关文章

  1. 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 ...

  2. Educational Codeforces Round 23 补题小结

    昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...

  3. 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 ...

  4. codeforces Educational Codeforces Round 24 (A~F)

    题目链接:http://codeforces.com/contest/818 A. Diplomas and Certificates 题解:水题 #include <iostream> ...

  5. Codeforces Round #585 (Div. 2) [补题]

    前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...

  6. Codeforces Round #429 (Div. 2) 补题

    A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...

  7. Codeforces Round #419 (Div. 1) 补题 CF 815 A-E

    A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. ...

  8. Codeforces Round #590 (Div. 3)补题

    要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ∅ √ 解 E 待定 F 传送门 第一 ...

  9. Educational Codeforces Round 65 E,F

    E. Range Deleting 题意:给出一个序列,定义一个操作f(x,y)为删除序列中所有在[x,y]区间内的数.问能使剩下的数单调不减的操作f(x,y)的方案数是多少. 解法:不会做,思维跟不 ...

随机推荐

  1. [codevs1050]棋盘染色 2

    [codevs1050]棋盘染色 2 试题描述 有一个5*N的棋盘,棋盘中的一些格子已经被染成了黑色,你的任务是对最少的格子染色,使得所有的黑色能连成一块. 输入 第一行一个整数N(<=100) ...

  2. HDU 6076 (动态规划)

    HDU 6076 Security Check Problem : 有两个长度为n的队列过安检,每个人有一个特征值.如果两个队列中的第一个人的特征值之差小于等于k,那么一次只能检查其中一个人,否则一次 ...

  3. 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]

    传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...

  4. Google SPDY

    SPDY(读作“SPeeDY”)是Google开发的基于TCP的应用层协议,用以最小化网络延迟,提升网络速度,优化用户的网络使用体验.SPDY并不是一种用于替代HTTP的协议,而是对HTTP协议的增强 ...

  5. IDEA添加作者注释

    1.打开IDEA的settings,然后在Editor下找到File and Code Templates 2.然后选择File Header 选择需要注释的的格式即可.

  6. CDI Services *Decoretions *Intercepters * Scope * EL\(Sp EL) *Eventmodel

    1.Decorators装饰器综述 拦截器是一种强大的方法在应用程序捕捉运行方法和解耦.拦截器可以拦截任何java类型的调用.  这使得拦截器适合解决事务管理,安全性,以及日记记录.  本质上说,拦截 ...

  7. EF关联

    public CustomerMap() { this.ToTable("Customer"); this.HasKey(c => c.Id); this.Property( ...

  8. spring-boot-starter-data-redis与spring-boot-starter-redis两个包的区别

    spring-boot-starter-data-redis: <?xml version="1.0" encoding="UTF-8"?> < ...

  9. CSS3 水波纹

    css3 动画设置水波纹,效果如下图: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  10. Java实现敏感词过滤代码

    原文:http://www.open-open.com/code/view/1445762764148 import java.io.BufferedReader; import java.io.Fi ...