Codeforces 1003

比赛链接

这么做是不是不太好啊233



A.Polycarp's Pockets

  1. #include <cstdio>
  2. #include <cctype>
  3. #include <algorithm>
  4. #define gc() getchar()
  5. const int N=500;
  6. int n,A[N],tm[N];
  7. inline int read()
  8. {
  9. int now=0,f=1;register char c=gc();
  10. for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
  11. for(;isdigit(c);now=now*10+c-'0',c=gc());
  12. return now*f;
  13. }
  14. int main()
  15. {
  16. n=read();
  17. for(int i=1; i<=n; ++i) ++tm[read()];
  18. int res=0;
  19. for(int i=1; i<=100; ++i) res=std::max(res,tm[i]);
  20. printf("%d",res);
  21. return 0;
  22. }

B.Binary String Constructing

  1. #include <cstdio>
  2. #include <cctype>
  3. #include <algorithm>
  4. #define gc() getchar()
  5. const int N=10000;
  6. int A,B,X;
  7. char s[N];
  8. inline int read()
  9. {
  10. int now=0,f=1;register char c=gc();
  11. for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
  12. for(;isdigit(c);now=now*10+c-'0',c=gc());
  13. return now*f;
  14. }
  15. int main()
  16. {
  17. A=read(),B=read(),X=read();//A:0 B:1
  18. int n=A+B;
  19. // if(X==1)
  20. // {
  21. // for(int i=1; i<=A; ++i) putchar('0');
  22. // for(int i=A+1; i<=n; ++i) putchar('1');
  23. // return 0;
  24. // }
  25. const char f=A>=B?'1':'0', s=A>=B?'0':'1';
  26. if(A>B) std::swap(A,B);
  27. for(int i=1; i<=X; ++i)
  28. putchar((i&1)?s:f), --((i&1)?B:A);
  29. if(X&1)
  30. {
  31. for(int i=X+1; i<=X+B; ++i) putchar(s);
  32. for(int i=X+B+1; i<=n; ++i) putchar(f);
  33. }
  34. else
  35. {
  36. for(int i=X+1; i<=X+A; ++i) putchar(f);
  37. for(int i=X+A+1; i<=n; ++i) putchar(s);
  38. }
  39. return 0;
  40. }

C.Intense Heat

  1. #include <cstdio>
  2. #include <cctype>
  3. #include <algorithm>
  4. #define gc() getchar()
  5. #define eps (1e-8)
  6. const int N=5007;
  7. int n,K,A[N];
  8. inline int read()
  9. {
  10. int now=0,f=1;register char c=gc();
  11. for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
  12. for(;isdigit(c);now=now*10+c-'0',c=gc());
  13. return now*f;
  14. }
  15. int main()
  16. {
  17. n=read(),K=read();
  18. for(int i=1; i<=n; ++i) A[i]=read();
  19. double ans=0;
  20. for(int i=1; i<=n; ++i)//O(n^2) 这种暴力我最会写了233
  21. {
  22. int sum=0;
  23. for(int j=i; j<=n; ++j)
  24. {
  25. sum+=A[j];
  26. if(j-i+1>=K) ans=std::max(ans,1.0*sum/(j-i+1));
  27. }
  28. }
  29. printf("%.10lf",ans);
  30. return 0;
  31. }

D.Coins and Queries

  1. #include <cmath>
  2. #include <cstdio>
  3. #include <cctype>
  4. #include <cstring>
  5. #include <algorithm>
  6. #define gc() getchar()
  7. const int N=2e5+5, INF=0x7fffffff;
  8. int n,Q,A[N],tot[999],num[999];
  9. inline int read()
  10. {
  11. int now=0;register char c=gc();
  12. for(;!isdigit(c);c=gc());
  13. for(;isdigit(c);now=now*10+c-'0',c=gc());
  14. return now;
  15. }
  16. inline int Count(int x){
  17. for(int i=0; i<31; ++i) if(x&(1<<i)) return i;
  18. }
  19. int Query()
  20. {//写的好像麻烦了 当时非常zz
  21. memcpy(num,tot,sizeof tot);
  22. int B=read(),ans=0;
  23. for(int i=30; ~i; --i)
  24. {
  25. if(!(B&(1<<i))) continue;
  26. if(num[i]) ++ans;
  27. else
  28. {
  29. int need=1<<i;
  30. for(int j=i-1; ~j&&need; --j)
  31. {
  32. if(!num[j]) continue;
  33. int v=std::min(num[j],need>>j);//need/(1<<j);//not ceil!
  34. ans+=v, need-=v*(1<<j), num[j]-=v;
  35. }
  36. if(need) return -1;
  37. }
  38. }
  39. return ans;
  40. }
  41. int main()
  42. {
  43. n=read(), Q=read();
  44. for(int i=1; i<=n; ++i) ++tot[Count(read())];
  45. while(Q--) printf("%d\n",Query());
  46. return 0;
  47. }

比赛结束后

E.Tree Constructing(贪心)

贪心策略显然 但可能要注意特殊情况(比如D=N-1,K=1)。

WA了四次结果结束后发现脑抽写错一行 改了就A了啊mmp

  1. #include <cstdio>
  2. #include <cctype>
  3. #include <algorithm>
  4. #define gc() getchar()
  5. const int N=4e5+7,M=N<<1;
  6. int n,D,K,now,dgr[N],Enum,H[N],nxt[M],to[M];
  7. inline int read()
  8. {
  9. int now=0;register char c=gc();
  10. for(;!isdigit(c);c=gc());
  11. for(;isdigit(c);now=now*10+c-'0',c=gc());
  12. return now;
  13. }
  14. inline void AddEdge(int u,int v)
  15. {
  16. ++dgr[u], to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
  17. ++dgr[v], to[++Enum]=u, nxt[Enum]=H[v], H[v]=Enum;
  18. }
  19. void Link(int x,int dep)
  20. {
  21. if(!dep) return;
  22. for(int i=K-dgr[x]; i>0&&now<n; --i) AddEdge(x,++now), Link(now,dep-1);
  23. }
  24. bool Solve()
  25. {
  26. if(D>=n) return 0;
  27. for(int i=1; i<=D; ++i) AddEdge(i,i+1);
  28. now=D+1;
  29. for(int i=2; i<=D&&now<n; ++i) Link(i,D-std::max(i-1,D+1-i));
  30. for(int i=1; i<=n; ++i) if(dgr[i]>K) return 0;
  31. // DFS1(1,1,0), Max=0, DFS1(V,V,0);
  32. // if(Max!=D) return 0;
  33. return now>=n;
  34. }
  35. void DFS_for_Ans(int x,int f)
  36. {
  37. for(int i=H[x]; i; i=nxt[i])
  38. if(to[i]!=f) printf("%d %d\n",x,to[i]), DFS_for_Ans(to[i],x);
  39. }
  40. int main()
  41. {
  42. n=read(), D=read(), K=read();
  43. if(Solve()) puts("YES"), DFS_for_Ans(1,1);
  44. else puts("NO");
  45. return 0;
  46. }

F.Abbreviation

  1. 待补

Codeforces Round #494 (Div 3) (A~E)的更多相关文章

  1. Codeforces Round #494 (Div. 3)

    刚好在考完当天有一场div3,就开了个小号打了,打的途中被辅导员喊去帮忙,搞了二十分钟-_-||,最后就出了四题,题解如下:题目链接:http://codeforces.com/contest/100 ...

  2. Codeforces Round #494 (Div. 3) D. Coins and Queries(贪心

    题目链接 题目大意:给你n个物品,第iii个物品价值aia_iai​,询问q次,问你能不能凑出价值为qiq_iqi​的物品. 小贪心吧.从大到小找,能拿就拿就行了. #include<bits/ ...

  3. Codeforces Round #494 (Div. 3) D. Coins and Queries (贪心,数学)

    题意:给你一组全是\(2^d\ (d\ge0)\)的数,询问q次,每次询问一个数,问这个数是否能够由原数组中的数相加得到,如果能,输出最少用多少个数,否则输出\(-1\). 题解:首先贪心得出结论:如 ...

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. node.js 开发环境搭建

    node.js下载地址 https://nodejs.org/download/ windows系统建议下载 msi 安装完成配置环境变量(根据安装路径来) NODE_PATH=C:\Program ...

  2. 使用solrJ管理索引——(十四)

    a)          什么是solrJ solrj是访问Solr服务的java客户端,提供索引和搜索的请求方法,SolrJ通常在嵌入在业务系统中,通过SolrJ的API接口操作Solr服务,如下图:

  3. 【洛谷】P1445 没占到1444的愤怒

    继续洛谷刷水日常,突然遇到一道不是很水的题目…… https://www.luogu.org/problem/show?pid=1445 题意:给定n(1<=n<=1000000),求方程 ...

  4. Python图片验证码降噪 — 8邻域降噪

    简介 图片验证码识别的可以分为几个步骤,一般用 Pillow 库或 OpenCV 来实现,这几个过程是: 1.灰度处理&二值化 2.降噪 3.字符分割 4.标准化 5.识别 所谓降噪就是把不需 ...

  5. javascript按照指定格式获取上一个月的日期

    //get pre month//get pre month function getPreMonth() { var date=new Date().Format("yyyy-MM-dd& ...

  6. Jenkins无法安装插件或首次安装插件界面提示Offline

    一.首先点击系统管理 二.点击插件管理 三.选择高级管理 四.将升级站点中的https改成http即可

  7. error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory

    一般我们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误, 比如: tmux: error while loading shared libraries: libevent-1.4.s ...

  8. SNMP相关命令

    SNMP的相关命令使用方法: snmpdelta 一直监视SNMP变量中的变化 linux:~ # snmpdelta -c public -v 1 -Cs -CT localhost IF-MIB: ...

  9. ZOJ 3962 Seven Segment Display(数位DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目大意: 有t组数据. 给你一个n,和8位的十六进制数s ...

  10. GreenPlum学习笔记:create or replace function创建函数

    原始表数据如下: 需求:现要求按分号“;”将rate_item列进行分割后插入到新的数据表中. CREATE OR REPLACE FUNCTION fun_gp_test_xxx_20181026( ...