如果最大值比剩余两个加起来的总和+1还大,就是NO,否则是YES

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int T;
  5. cin>>T;
  6. while(T--){
  7. vector<int> a(3);
  8. for(int i=0;i<3;i++)
  9. cin>>a[i];
  10. sort(a.begin(),a.end());
  11. if(a[2]>a[0]+a[1]+1) puts("No");
  12. else puts("Yes");
  13. }
  14. }

  

先不要去考虑跳过的问题,就让他一直向前走,并且一直减,并且记录途中遇到的礼物最大值,这样有两种情况

case1:直接走完,答案就是0

case2:停在某一个位置,我们一定会选择所有可能跳过的礼物中最大的,因为必须要放弃一个,肯定要放弃其中最大的

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int T;
  7. scanf("%d",&T);
  8. while(T--){
  9. int n,sum;
  10. scanf("%d%d",&n,&sum);
  11. vector<int> a(n);
  12. for(int i=0;i<n;i++)
  13. scanf("%d",&a[i]);
  14. int pos=0;
  15. int i;
  16. for(i=0;i<n;i++){
  17. if(sum>=a[i]) {
  18. sum-=a[i];
  19. }
  20. else {
  21. if(a[pos]<a[i]) pos=i;
  22. break;
  23. }
  24. if(a[pos]<a[i]) pos=i;
  25. }
  26. if(i==n) printf("0\n");
  27. else{
  28. printf("%d\n",pos+1);
  29. }
  30. }
  31. }

  

对于被拿出来的,不需要去管他究竟是按什么放回去的,但是可以肯定的是必然有一种方案是最优的,使得如果不取更深的礼物的话花费一定是1

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn=1e5+5;
  6.  
  7. int a[maxn],b[maxn],pos[maxn];
  8.  
  9. int main(){
  10. int T;
  11. scanf("%d",&T);
  12. while(T--){
  13. int n,m;
  14. scanf("%d%d",&n,&m);
  15. for(int i=0;i<n;i++)
  16. scanf("%d",&a[i]),pos[a[i]]=n-i;
  17. for(int i=0;i<m;i++)
  18. scanf("%d",&b[i]);
  19. int in=n,out=0;
  20. long long ans=0;
  21. for(int i=0;i<m;i++){
  22. if(pos[b[i]]<=in) {
  23. ans+=2*(in-pos[b[i]]+out)+1;
  24. in=pos[b[i]]-1;
  25. out=n-i-1-in;
  26. }
  27. else ans++,out--;
  28. }
  29. printf("%lld\n",ans);
  30. }
  31. }

  

遍历每一个礼物,很容易算出每一个礼物被选中的概率,然后考虑有多少个人需要这个礼物,假设为cnt,这个可以预处理出来,选中这些人的概率为cnt/n

两个相乘即可,所有的情况加起来即可

  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int maxn=1e6+5;
  6. const int P=998244353;
  7.  
  8. int add(int a,int b){
  9. int ans=a+b;
  10. if(ans>=P) ans-=P;
  11. return ans;
  12. }
  13.  
  14. int mul(int a,int b){
  15. return 1ll*a*b%P;
  16. }
  17.  
  18. int qpow(int a,int n){
  19. int ans=1;
  20. for(;n;n>>=1,a=1ll*a*a%P)
  21. if(n&1) ans=1ll*ans*a%P;
  22. return ans;
  23. }
  24.  
  25. vector<int> a[maxn];
  26.  
  27. int inv[maxn];
  28.  
  29. int main(){
  30. int n;
  31. scanf("%d",&n);
  32. vector<int> cnt(maxn,0);
  33. for(int i=0;i<n;i++){
  34. int x;
  35. scanf("%d",&x);
  36. a[i].resize(x);
  37. for(int j=0;j<x;j++)
  38. scanf("%d",&a[i][j]);
  39. for(int j=0;j<x;j++)
  40. cnt[a[i][j]]++;
  41. }
  42. for(int i=0;i<maxn;i++)
  43. inv[i]=qpow(i,P-2);
  44. int ans=0;
  45. for(int i=0;i<n;i++){
  46. for(int j=0;j<a[i].size();j++){
  47. ans=add(ans,mul(mul(inv[n],inv[a[i].size()]),mul(inv[n],cnt[a[i][j]])));
  48. }
  49. }
  50. printf("%d\n",ans);
  51. }

  

Educational Codeforces Round 79 (Rated for Div. 2) Finished (A-D)的更多相关文章

  1. Educational Codeforces Round 81 (Rated for Div. 2)E(线段树)

    预处理把左集划分为大小为1~i-1时,把全部元素都移动到右集的代价,记作sum[i]. 然后枚举终态时左集的大小,更新把元素i 留在/移动到 左集的代价. 树状数组/线段树处理区间修改/区间查询 #d ...

  2. Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)

    这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...

  3. Educational Codeforces Round 79 (Rated for Div. 2) - D. Santa's Bot(数论)

    题意:有$n$个孩子,第$i$个孩子有$k[i]$件想要的礼物,第$j$个礼物为$a[i][j]$,现在随机挑一个孩子,从他想要的礼物里面随机挑一个,然后送给另一个孩子$($这个孩子可以和第一个孩子是 ...

  4. CF codeforces A. New Year Garland【Educational Codeforces Round 79 (Rated for Div. 2)】

    A. New Year Garland time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Educational Codeforces Round 60 (Rated for Div. 2)D(思维,DP,快速幂)

    #include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;unordered_map<long ...

  6. Educational Codeforces Round 60 (Rated for Div. 2)E(思维,哈希,字符串,交互)

    #include <bits/stdc++.h>using namespace std;int main(){ string t; cin>>t; int n=t.size() ...

  7. Educational Codeforces Round 61 (Rated for Div. 2)F(区间DP,思维,枚举)

    #include<bits/stdc++.h>typedef long long ll;const int inf=0x3f3f3f3f;using namespace std;char ...

  8. Educational Codeforces Round 61 (Rated for Div. 2)D(二分,模拟,思维)

    #include<bits/stdc++.h>using namespace std;typedef long long ll;int n,k;ll a[200007],b[200007] ...

  9. Educational Codeforces Round 57 (Rated for Div. 2)D(动态规划)

    #include<bits/stdc++.h>using namespace std;char s[100007];long long a[100007];long long dp[100 ...

随机推荐

  1. 小白学 Python 数据分析(4):Pandas (三)数据结构 DataFrame

    在家为国家做贡献太无聊,不如跟我一起学点 Python 人生苦短,我用 Python 前文传送门: 小白学 Python 数据分析(1):数据分析基础 小白学 Python 数据分析(2):Panda ...

  2. Go语言实现:【剑指offer】二叉树的深度

    该题目来源于牛客网<剑指offer>专题. 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. Go语言实现: /** ...

  3. 【题解】[P1045] 麦森数

    题目 题目描述 形如2^P-1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果P是个素数,2^P-1 不一定也是素数.到1998年底,人们已找到了37个麦森数.最大的一个是P=30213 ...

  4. SpringBoot2.x操作缓存的新姿势

    一.介绍 spring cache 是spring3版本之后引入的一项技术,可以简化对于缓存层的操作,spring cache与springcloud stream类似,都是基于抽象层,可以任意切换其 ...

  5. VFP 的 CursorAdapter 相关

    VFP 的 CursorAdapter 是在VFP 8 中增加的最重要的新功能,它提供了一种采用统一接口的方式来访问远程数据源. 现在正值新冠肺炎期间,闲着也是闲着,在整理原理的资料时,发现十多年前的 ...

  6. k8s系列---资源指标API及自定义指标API

    不得不说千万不要随意更改版本,我用的1.13的版本,然后学到这一步时,还因yaml文件不同,卡住了很久,然后各种google才找到解决办法  https://www.linuxea.com/2112. ...

  7. Zookeeper 介绍 原理

    简介: ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务.       它Google的Chubby一个开源的实现,在分布式协调技术方面做得比较好的就是Google的Chubby还有 ...

  8. ubuntu16.04 自建源

    来自于https://www.cnblogs.com/liangqihui/p/7150066.html APT本地源的搭建(可用于局域网apt-get源搭建或者本地源) 本文档介绍使用apt-mir ...

  9. Linux 配置 DNS

    这里不讨论如何在linux上搭建一台DNS服务器: 这里讨论的是 配置 linux系统,让其能够解析域名,使用户可以流畅使用Internet 先了解几个文件,位于/etc目录下的有:hosts,hos ...

  10. 细读jsr中的yield语义,或者不是我们想象中的那样

    这只是我的个人观点,如有错误,希望你可以指出. 首先英文原版 中文译版 我觉得“不需要”还会让人产生误解,应该译为不一定要. 很多时候会被断章取义地理解,我们一定要有“不一定”,“可能”的意识,下面给 ...