A. There Are Two Types Of Burgers

题意:

给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉

一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个牛肉

求能得到的最多的钱

直接贪心,哪个比较贵就选哪个做,剩下的材料再做另一个

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline int read()
  9. {
  10. int x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. const int N=2e5+;
  16. int T,n,a,b,va,vb;
  17. int main()
  18. {
  19. T=read();
  20. while(T--)
  21. {
  22. n=read(),a=read(),b=read();
  23. va=read(),vb=read();
  24. if(va>vb) { int t=min(a,n/); printf("%d\n",va*t+vb*min(b,(n-t*)/)); }
  25. else { int t=min(b,n/); printf("%d\n",vb*t+va*min(a,(n-t*)/)); }
  26. }
  27. return ;
  28. }

B. Square Filling

题意:

给一个矩阵,求把一个空矩阵进行一些操作后能否得到给定矩阵

操作为选择一个 $2*2$ 的子矩阵并把里面的数全部变成 $1$,不要求最少次数,如果能则输出具体操作

显然枚举所有左上角看看能不能操作,能的话就尽量操作

最后判断一下是否得到给定矩阵就行了

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<vector>
  7. using namespace std;
  8. typedef long long ll;
  9. inline int read()
  10. {
  11. int x=,f=; char ch=getchar();
  12. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  13. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  14. return x*f;
  15. }
  16. const int N=;
  17. int n,m,a[N][N],b[N][N];
  18. vector <int> X,Y;
  19. int main()
  20. {
  21. n=read(),m=read();
  22. for(int i=;i<=n;i++)
  23. for(int j=;j<=m;j++) a[i][j]=read();
  24. for(int i=;i<=n;i++)
  25. for(int j=;j<=m;j++)
  26. {
  27. if(a[i][j]&&a[i+][j]&&a[i][j+]&&a[i+][j+])
  28. {
  29. X.push_back(i); Y.push_back(j);
  30. b[i][j]=b[i+][j]=b[i][j+]=b[i+][j+]=;
  31. }
  32. }
  33. for(int i=;i<=n;i++)
  34. for(int j=;j<=m;j++) if(a[i][j]&&!b[i][j]) { printf("-1\n"); return ; }
  35. int ans=X.size(); printf("%d\n",ans);
  36. for(int i=;i<ans;i++) printf("%d %d\n",X[i],Y[i]);
  37. return ;
  38. }

C. Gas Pipeline

题意:

铺水管,需要支柱和管道,各有价格,从 $0$ 铺到 $n$ 求最小花费

管道高度可以为 $1$ 或 $2$,高度为 $1$ 时只要一个支柱,为 $2$ 时要两个,管道高度变化的时候要格外一个管道

某些位置强制管道高度为 $2$

显然考虑 $dp$,设 $f[i][0/1]$ 当前铺到位置 $i$ ,高度为 $1,2$ 时的最小花费,转移显然,具体看代码,注意$long\ long$

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline int read()
  9. {
  10. int x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. const int N=2e5+;
  16. const ll INF=1e18;
  17. int T,n,va,vb;
  18. char s[N];
  19. ll f[N][];
  20. int main()
  21. {
  22. T=read();
  23. while(T--)
  24. {
  25. n=read(),va=read(),vb=read();
  26. scanf("%s",s+);
  27. f[][]=vb; f[][]=INF;//初始高度必须为1
  28. for(int i=;i<=n;i++)
  29. {
  30. f[i][]=min(f[i-][]+va+vb,f[i-][]+va*+vb);
  31. f[i][]=min(f[i-][]+va*+vb*,f[i-][]+va+vb*);
  32. if(s[i]==''||s[i+]=='') f[i][]=INF;
  33. }
  34. printf("%lld\n",f[n][]);
  35. }
  36. return ;
  37. }

D. Number Of Permutations

题意:

给一个数列 $a$ ,求合法排列方案数,不合法指 $a$ 的某一排列中某一维单调不减

见计数想容斥

先考虑一个很 $naive$ 的东西,给一个数列求单调不减的排列数,值同样的数也看成不同的

显然每个值互相之间不能交换,只能同一个值之间乱换,同一个值的贡献就是 这个值的所有数全排列,整个数列的答案就是每个值贡献乘法原理乘起来

回到原问题,数列变成两维了,感觉合法不好求,考虑求出不合法的方案

显然答案就是:全排列方案数 减 强制一个不合法方案数 加 两个都不合法方案数,然后就变成求单调不减的排列数了

两个都不合法的方案数也很好求,具体看代码

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline int read()
  9. {
  10. int x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. const int N=6e5+,mo=;
  16. int n;
  17. ll fac[N],ans;
  18. struct dat{
  19. int a,b;
  20. }d[N];
  21. inline bool cmp1(const dat &A,const dat &B) { return A.a!=B.a ? A.a<B.a : A.b<B.b; }
  22. inline bool cmp2(const dat &A,const dat &B) { return A.b!=B.b ? A.b<B.b : A.a<B.a; }
  23. int main()
  24. {
  25. n=read();
  26. fac[]=; for(int i=;i<=n;i++) d[i].a=read(),d[i].b=read(),fac[i]=fac[i-]*i%mo;
  27. ans=fac[n];//全排列
  28. sort(d+,d+n+,cmp1); ll t=; int cnt=;
  29. for(int i=;i<=n;i++)
  30. {
  31. if(i==||d[i].a==d[i-].a) cnt++;
  32. else t=t*fac[cnt]%mo,cnt=;
  33. }
  34. t=t*fac[cnt]%mo;
  35. ans-=t;//第一维不合法
  36. sort(d+,d+n+,cmp2); t=; cnt=;
  37. for(int i=;i<=n;i++)
  38. {
  39. if(i==||d[i].b==d[i-].b) cnt++;
  40. else t=t*fac[cnt]%mo,cnt=;
  41. }
  42. t=t*fac[cnt]%mo;
  43. ans-=t;/*第二维不合法*/ t=; cnt=;
  44. for(int i=;i<=n;i++)
  45. {
  46. if(i==||(d[i].a==d[i-].a&&d[i].b==d[i-].b)) cnt++;
  47. else t=t*fac[cnt]%mo,cnt=;
  48. if(i!=&&d[i].a<d[i-].a) t=;//注意可能不存在两维同时不减的情况
  49. }
  50. t=t*fac[cnt]%mo;
  51. ans+=t;//两维都不合法
  52. printf("%lld\n",(ans%mo+mo)%mo);
  53. return ;
  54. }

E. XOR Guessing

人生第一道交互题 $2333$

让你猜一个 $[0,2^{14}-1]$ 的数,你只能询问两次,每次你给出 $100$ 个数,系统会在你给的 $100$ 个数里面随便找一个值 $v$ 并返回答案与 $v$ 的异或值

要如何通过两次询问确定这个答案,询问时你给出的所有数必须互不相同

考虑一下如果能全给出 $0$ ,那么答案很显然,这样问一次就够了

考虑先确定答案二进制下的前半段,那么我们只要给出 $100$ 个二进制下高的 $7$ 位全为 $0$ 的数,不论系统返回什么值,高位的 $7$ 位就一定能确定

然后我们再问低位的 $7$ 位,同样给出 $100$ 个二进制下 低的 $7$ 位全为 $0$ 的数即可

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. int ans;
  9. int main()
  10. {
  11. cout<<"? ";
  12. for(int i=;i<=;i++)cout<<i<<" "; cout<<<<endl;
  13. int t; cin>>t;
  14. ans=t>>;
  15. cout<<"? ";
  16. for(int i=;i<=;i++) cout<<(i<<)<<" "; cout<<(<<)<<endl;
  17. int res; cin>>res;
  18. ans=(ans<<)|(res ^ ((res>>)<<) );
  19. cout<<"! "<<ans<<endl;
  20. return ;
  21. }

F. Remainder Problem

题意:

给一个长度为 $5*10^5$ 的数列,初始全为 $0$,进行不超过 $5*10^5$ 次询问

把某个位置值加上一个数,或者询问所有 位置模 $x$ 意义下等于 $y$ 的位置的数值之和

发现如果 $x$ 一直很大,那么我们直接暴力枚举即可,如果 $x$ 一直很小,我们只要随便开个二维数组维护一下就行

考虑分类讨论一下,把询问分成大的和小的,大的就暴力枚举,小的就从二维数组里面查询

分界点取 $\sqrt {n}$ 或者某个差不多的数即可,复杂度 $O(n \sqrt {n})$

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. typedef long long ll;
  8. inline int read()
  9. {
  10. int x=,f=; char ch=getchar();
  11. while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
  12. while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
  13. return x*f;
  14. }
  15. const int N=5e5,M=;
  16. int n;
  17. ll A[N+],sum[M+][M+];
  18. int main()
  19. {
  20. n=read(); int opt,a,b;
  21. for(int i=;i<=n;i++)
  22. {
  23. opt=read(),a=read(),b=read();
  24. if(opt==)
  25. {
  26. A[a]+=b;
  27. for(int i=;i<=M;i++) sum[i][a%i]+=b;
  28. }
  29. if(opt==)
  30. {
  31. if(a>M)
  32. {
  33. ll ans=;
  34. for(int i=b;i<=N;i+=a) ans+=A[i];
  35. printf("%lld\n",ans);
  36. }
  37. else printf("%lld\n",sum[a][b]);
  38. }
  39. }
  40. return ;
  41. }

G. Indie Album

比赛的时候竟然没看出来 $woc$,[NOI2011]阿狸的打字机 了解一下,差不多的做法

佛了

Educational Codeforces Round 71 (Rated for Div. 2) Solution的更多相关文章

  1. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  2. Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题

    Educational Codeforces Round 71 (Rated for Div. 2)-E. XOR Guessing-交互题 [Problem Description] ​ 总共两次询 ...

  3. Educational Codeforces Round 71 (Rated for Div. 2)E. XOR Guessing

    一道容斥题 如果直接做就是找到所有出现过递减的不同排列,当时硬钢到自闭,然后在凯妹毁人不倦的教导下想到可以容斥做,就是:所有的排列设为a,只考虑第一个非递减设为b,第二个非递减设为c+两个都非递减的情 ...

  4. Educational Codeforces Round 71 (Rated for Div. 2) E XOR Guessing (二进制分组,交互)

    E. XOR Guessing time limit per test1 second memory limit per test256 megabytes inputstandard input o ...

  5. [暴力] Educational Codeforces Round 71 (Rated for Div. 2) B. Square Filling (1207B)

    题目:http://codeforces.com/contest/1207/problem/B   B. Square Filling time limit per test 1 second mem ...

  6. [贪心,dp] Educational Codeforces Round 71 (Rated for Div. 2) C. Gas Pipeline (1207C)

    题目:http://codeforces.com/contest/1207/problem/C   C. Gas Pipeline time limit per test 2 seconds memo ...

  7. Educational Codeforces Round 71 (Rated for Div. 2)

    传送门 A.There Are Two Types Of Burgers 签到. B.Square Filling 签到 C.Gas Pipeline 每个位置只有"高.低"两种状 ...

  8. Remainder Problem(分块) Educational Codeforces Round 71 (Rated for Div. 2)

    引用:https://blog.csdn.net/qq_41879343/article/details/100565031 下面代码写错了,注意要上面这种.查:2  800  0,下面代码就错了. ...

  9. XOR Guessing(交互题+思维)Educational Codeforces Round 71 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1207/problem/E 答案guessing(0~2^14-1) 有两次机会,内次必须输出不同的100个数,每次系统会随机挑一个你给 ...

随机推荐

  1. python3安装web.py

    今天准备测试代理池IPProxyPool获取到ip的质量,在安装web.py的时候遇到了些问题,在此记录一下. 1.安装资料 web.py官网:http://webpy.org/ web.py的git ...

  2. 冲刺阶段——Day3

    [今日进展] 完善黄金点游戏的算法与代码架构. 将文字界面改编为图形界面 码云链接:https://gitee.com/jxxydwt1999/20175215-java/blob/master/Go ...

  3. zookeeper系列 (第三章 :zookeeper 的使用)

    接上一章,在启动客户端之后,开始通过命令操作zookeeper 服务. 一:zookeeper 的基础命令 1.通过zkCli.sh 命令与主机建立一个会话 2.开始在会话中执行命令:写入Znode. ...

  4. Flutter移动电商实战 --(17)首页_楼层区域的编写

    1.楼层标题组件 该组件非常简单,只接收一个图片地址,然后显示即可: class FloorTitle extends StatelessWidget { final String picture_a ...

  5. python3 django项目从项目中导出依赖包

    1. 在项目的根目录中使用mac终端执行命令, pip3 freeze > requirements.txt #requirements.txt只是个名字可以随便起,一般默认为requireme ...

  6. c++ map multimap操作

    #include <iostream>#include <map>#include <string> using namespace std; int main() ...

  7. ubuntu18 faster-rcnn

    luo@luo-All-Series:~/MyFile$ luo@luo-All-Series:~/MyFile$ luo@luo-All-Series:~/MyFile$ git clone htt ...

  8. 小记LoadRunner 11 安装VC2005运行环境报错处理

    这几天在做性能优化,需要在虚拟机里装个LoadRunner 11.从测试同学那里搞来安装包,按照文档提示安装系统运行环境,提示我要装VC2005 SP1. 安装程序自己安装,报错.截图如下. 于是我又 ...

  9. scalaTest的初步使用

    1. 概述 ScalaTest是scala生态系统中最流行和灵活的测试工具,可以测试scala.js.java代码. 2. ScalaTest的特性 a. ScalaTest的核心是套件(suite) ...

  10. Linux系统管理----LVM逻辑卷和磁盘配额作业习题

    1.为主机增加80G SCSI 接口硬盘 2.划分三个各20G的主分区 [root@localhost chen]# fdisk /dev/sdb 命令(输入 m 获取帮助):n Partition ...