A:显然构造一组只包含1和2面值的数据即可。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<algorithm>
  7. using namespace std;
  8. #define ll long long
  9.  
  10. char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
  11. int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
  12. int read()
  13. {
  14. int x=0,f=1;char c=getchar();
  15. while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
  16. while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
  17. return x*f;
  18. }
  19.  
  20. signed main()
  21. {
  22. #ifndef ONLINE_JUDGE
  23. freopen("a.in","r",stdin);
  24. freopen("a.out","w",stdout);
  25. #endif
  26. int n=read();
  27. cout<<n*2-1<<' '<<2<<endl;
  28. cout<<1<<' '<<2;
  29. return 0;
  30. //NOTICE LONG LONG!!!!!
  31. }

  B:显然两种pizza的分配应尽可能贴近第二种更优和第一种更优的人数关系。于是在这个边界附近±1暴力枚举一下,然后贪心非常显然。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<algorithm>
  7. using namespace std;
  8. #define ll long long
  9. #define N 100010
  10. char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
  11. int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
  12. int read()
  13. {
  14. int x=0,f=1;char c=getchar();
  15. while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
  16. while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
  17. return x*f;
  18. }
  19. int n,m;
  20. ll t=0,ans=0;
  21. struct data
  22. {
  23. int x,y,z;
  24. bool operator <(const data&a) const
  25. {
  26. return y-x>a.y-a.x;
  27. }
  28. }a[N];
  29. bool cmp(const data&x,const data&y)
  30. {
  31. return abs(x.y-x.x)>abs(y.y-y.x);
  32. }
  33. void check(ll k)
  34. {
  35. if (k<0||k>t) return;
  36. ll x=1ll*k*m,y=(t-k)*m,s=0;
  37. for (int i=1;i<=n;i++)
  38. if (a[i].y>a[i].x)
  39. {
  40. if (a[i].z<=x) s+=1ll*a[i].y*a[i].z,x-=a[i].z;
  41. else if (x) s+=1ll*a[i].y*x,s+=1ll*a[i].x*(a[i].z-x),y-=a[i].z-x,x=0;
  42. else s+=1ll*a[i].x*a[i].z,y-=a[i].z;
  43. }
  44. else
  45. {
  46. if (a[i].z<=y) s+=1ll*a[i].x*a[i].z,y-=a[i].z;
  47. else if (y) s+=1ll*a[i].x*y,s+=1ll*a[i].y*(a[i].z-y),x-=a[i].z-y,y=0;
  48. else s+=1ll*a[i].y*a[i].z,x-=a[i].z;
  49. }
  50. ans=max(ans,s);
  51. }
  52. signed main()
  53. {
  54. #ifndef ONLINE_JUDGE
  55. freopen("a.in","r",stdin);
  56. freopen("a.out","w",stdout);
  57. #endif
  58. n=read(),m=read();
  59. for (int i=1;i<=n;i++) t+=a[i].z=read(),a[i].x=read(),a[i].y=read();
  60. sort(a+1,a+n+1);
  61. t=(t-1)/m+1;
  62. ll x=0;for (int i=1;i<=n;i++) if (a[i].y>a[i].x) x+=a[i].z;else break;
  63. sort(a+1,a+n+1,cmp);
  64. for (ll i=x/m-2;i<=x/m+2;i++) check(i);
  65. sort(a+1,a+n+1);
  66. x=0;for (int i=1;i<=n;i++) if (a[i].y>=a[i].x) x+=a[i].z;else break;
  67. sort(a+1,a+n+1,cmp);
  68. for (ll i=x/m-2;i<=x/m+2;i++) check(i);
  69. cout<<ans;
  70. return 0;
  71. //NOTICE LONG LONG!!!!!
  72. }

  D:注意到在某一天卖出再买进对答案是没有影响的。于是维护一个小根堆,每次取出堆顶与当前天价格比较,若能赚钱则计入答案并将堆顶弹出,相当于在堆顶那天买进然后在当前天卖出,然后将当前天价格入堆。我们还需要支持一个反悔操作,即更换买进天的匹配对象,容易发现把当前天价格再入一次堆就可以了。大约是在模拟费用流。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<algorithm>
  7. #include<queue>
  8. #include<vector>
  9. using namespace std;
  10. #define ll long long
  11. #define N 300010
  12. char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
  13. int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
  14. int read()
  15. {
  16. int x=0,f=1;char c=getchar();
  17. while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
  18. while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
  19. return x*f;
  20. }
  21. int n,a[N];
  22. ll ans=0;
  23. priority_queue<int,vector<int>,greater<int> > q;
  24. signed main()
  25. {
  26. #ifndef ONLINE_JUDGE
  27. freopen("d.in","r",stdin);
  28. freopen("d.out","w",stdout);
  29. #endif
  30. n=read();
  31. for (int i=1;i<=n;i++) a[i]=read();
  32. for (int i=1;i<=n;i++)
  33. {
  34. if (!q.empty()&&q.top()<a[i])
  35. {
  36. ans+=a[i]-q.top();
  37. int x=q.top();q.pop();
  38. q.push(a[i]);
  39. }
  40. q.push(a[i]);
  41. }
  42. cout<<ans;
  43. return 0;
  44. //NOTICE LONG LONG!!!!!
  45. }

  C:期望考虑倒推,但难以计算重置带来的影响。于是考虑先固定住重置的作用,即二分答案,这样重置之后就相当于可以用等于答案的时间直接通关。然后就可以dp了,即设f[i][j]为i~n关要用至多j时间通关的话最少要花多久。最后得到f[1][m],判断其和二分出的答案的大小,若比其大说明一开始就得重置,这显然说明二分出来的答案小了;反之亦然。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<cstring>
  6. #include<algorithm>
  7. using namespace std;
  8. #define ll long long
  9. #define N 110
  10. #define inf ((double)100000000000)
  11. char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
  12. int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
  13. int read()
  14. {
  15. int x=0,f=1;char c=getchar();
  16. while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
  17. while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
  18. return x*f;
  19. }
  20. int n,m,a[N],b[N],p[N];
  21. double f[N][N*N];
  22. signed main()
  23. {
  24. #ifndef ONLINE_JUDGE
  25. freopen("a.in","r",stdin);
  26. freopen("a.out","w",stdout);
  27. #endif
  28. n=read(),m=read();
  29. for (int i=1;i<=n;i++) a[i]=read(),b[i]=read(),p[i]=read();
  30. double l=0,r=inf,ans;
  31. for (int _=1;_<=100;_++)
  32. {
  33. double mid=(l+r)/2;
  34. for (int i=n;i>=1;i--)
  35. for (int j=0;j<=m;j++)
  36. {
  37. f[i][j]=0.01*((a[i]+(j>=a[i]?f[i+1][j-a[i]]:mid))*p[i]+(b[i]+(j>=b[i]?f[i+1][j-b[i]]:mid))*(100-p[i]));
  38. if (i>1) f[i][j]=min(f[i][j],mid);
  39. }
  40. if (f[1][m]>mid) ans=mid,l=mid;else r=mid;
  41. }
  42. printf("%.11f",ans);
  43. return 0;
  44. //NOTICE LONG LONG!!!!!
  45. }

  

Codeforces Round #437 Div. 1的更多相关文章

  1. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  2. Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2)

    Problem A Between the Offices 水题,水一水. #include<bits/stdc++.h> using namespace std; int n; ]; i ...

  3. Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E

    题意:减前面的数,加后面的数,保证最后不剩下数,加减次数要相同: 题解:emmmmm,看出是个贪心,先对价值排序,相同就对下标排序,规律是每次找第一个,然后从后往前找没有使用过的下表比他大的第一个,相 ...

  4. 【Codeforces Round #437 (Div. 2) A】Between the Offices

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...

  5. 【Codeforces Round #437 (Div. 2) B】Save the problem!

    [链接]h在这里写链接 [题意]     给你一个金额N,和硬币的类型总数M;     (完全背包),然后问你组成N的方案数.     使得,用这些硬币组成价值为N的金额的方案数为A;     现在A ...

  6. 【Codeforces Round #437 (Div. 2) C】 Ordering Pizza

    [链接]h在这里写链接 [题意]     给你参赛者的数量以及一个整数S表示每块披萨的片数.     每个参数者有3个参数,si,ai,bi;     表示第i个参赛者它要吃的披萨的片数,以及吃一片第 ...

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

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

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

  9. Codeforces Round #368 (Div. 2)

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

随机推荐

  1. [翻译] 如何在 ASP.Net Core 中使用 Consul 来存储配置

    [翻译] 如何在 ASP.Net Core 中使用 Consul 来存储配置 原文: USING CONSUL FOR STORING THE CONFIGURATION IN ASP.NET COR ...

  2. 【C#复习总结】细说表达式树

    1 前言 系类1:细说委托 系类2:细说匿名方法 系列3:细说Lambda表达式 系列4:细说泛型委托 系列5:细说表达式树 系列6:细说事件 涛声依旧,再续前言,接着用大佬的文章作为开头. 表达式树 ...

  3. Windows下如何更新 CodeBlocks 中的 MinGW 使其支持新版本 C++

    转自:http://blog.csdn.net/wtfmonking/article/details/17487705 虽然 CodeBlocks16.01 已经是最新版了,但其中的 MinGW 仍然 ...

  4. 大神教你Debian GNU/Linux 9.7 “Stretch” Live和安装镜像开放下载

    Debian项目团队于昨天发布了Debian GNU/Linux 9 "Stretch" 的第7个维护版本更新,重点修复了APT软件管理器中存在的安全漏洞.在敦促每位用户尽快升级系 ...

  5. 同步和异步概念(由DZW前端框架引发的百度地图api无法加载问题总结)

    首先概念: 在计算机领域,同步就是指一个进程在执行某个请求的时候,若该请求需要一段时间才能返回信息,那么这个进程将会一直等待下去,直到收到返回信息才继续执行下去:异步是指进程不需要一直等下去,而是继续 ...

  6. NSAssert和NSParameterAssert

    2016.05.05 18:34* 字数 861 阅读 5127评论 0喜欢 17 https://www.jianshu.com/p/3072e174554f NSAssert和NSParamete ...

  7. pip国内镜像

    [国内镜像] 中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple 清华:https://pypi.tuna.tsinghua.edu.cn/simpl ...

  8. Docker Compose vs. Dockerfile

    Docker Compose vs. Dockerfile - which is better? - Stack Overflowhttps://stackoverflow.com/questions ...

  9. cent6.x配置主机名及静态网络

    # 修改网卡名为NAME="eth0" [root@jenkins ~]# -persistent-net.rules # This file was automatically ...

  10. 了解真实的rem手机屏幕适配

    rem 作为一个低调的长度单位,由于手机端网页的兴起,在屏幕适配中得到重用.使用 rem 前端开发者可以很方便的在各种屏幕尺寸下,通过等比缩放的方式达到设计图要求的效果. rem 的官方定义『The ...