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

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

  

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

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

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

#include<bits/stdc++.h>

using namespace std;

int main(){
int T;
scanf("%d",&T);
while(T--){
int n,sum;
scanf("%d%d",&n,&sum);
vector<int> a(n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int pos=0;
int i;
for(i=0;i<n;i++){
if(sum>=a[i]) {
sum-=a[i];
}
else {
if(a[pos]<a[i]) pos=i;
break;
}
if(a[pos]<a[i]) pos=i;
}
if(i==n) printf("0\n");
else{
printf("%d\n",pos+1);
}
}
}

  

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

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

int a[maxn],b[maxn],pos[maxn];

int main(){
int T;
scanf("%d",&T);
while(T--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d",&a[i]),pos[a[i]]=n-i;
for(int i=0;i<m;i++)
scanf("%d",&b[i]);
int in=n,out=0;
long long ans=0;
for(int i=0;i<m;i++){
if(pos[b[i]]<=in) {
ans+=2*(in-pos[b[i]]+out)+1;
in=pos[b[i]]-1;
out=n-i-1-in;
}
else ans++,out--;
}
printf("%lld\n",ans);
}
}

  

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

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

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e6+5;
const int P=998244353; int add(int a,int b){
int ans=a+b;
if(ans>=P) ans-=P;
return ans;
} int mul(int a,int b){
return 1ll*a*b%P;
} int qpow(int a,int n){
int ans=1;
for(;n;n>>=1,a=1ll*a*a%P)
if(n&1) ans=1ll*ans*a%P;
return ans;
} vector<int> a[maxn]; int inv[maxn]; int main(){
int n;
scanf("%d",&n);
vector<int> cnt(maxn,0);
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
a[i].resize(x);
for(int j=0;j<x;j++)
scanf("%d",&a[i][j]);
for(int j=0;j<x;j++)
cnt[a[i][j]]++;
}
for(int i=0;i<maxn;i++)
inv[i]=qpow(i,P-2);
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<a[i].size();j++){
ans=add(ans,mul(mul(inv[n],inv[a[i].size()]),mul(inv[n],cnt[a[i][j]])));
}
}
printf("%d\n",ans);
}

  

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. num13---外观模式/过程模式

    假设家庭影院有一系列设备,每个设备都有各种开闭等功能性方法,使用家庭影院功能的时候,需要进行各个设备的一系列操作,繁琐麻烦. 现在提供一个外观类,在里面定义操作流程,客户端只需要和外观类进行接口交互即 ...

  2. WLAN802.11

    IEEE 802.11,1997年,原始标准(2Mbit/s,播在2.4GHz).DSSS, FHSS.该协议的一大缺点是它提供了太多的选择使得互操作性很难实现.所以它不严密,更像是一个beta标准, ...

  3. IIS停止服务 报错Connections_Refused

    IIS版本6.0  无故停止工作.         重启IIS 没有效果,必须重启web服务器.出现客户端无法访问Web服务器上的站点,错误信息提示为"页面无法显示"的情况.登录服 ...

  4. 我说我了解集合类,面试官竟然问我为啥HashMap的负载因子不设置成1!?

    在Java基础中,集合类是很关键的一块知识点,也是日常开发的时候经常会用到的.比如List.Map这些在代码中也是很常见的. 个人认为,关于HashMap的实现,JDK的工程师其实是做了很多优化的,要 ...

  5. 杭电------2097 Sky数(C语言写)

    //这个题没有一次过,哈哈哈哈,题意理解错了,开始还以为是必须加起来等于22呢 //其实就是依次算出个进制下的和,虽然每个循环最多循环四次,但是还是加上必要的判断,想办法让 //提前结束 #inclu ...

  6. java设计模式 - 单例模式(干货)

    深度讲解23种设计模式,力争每种设计模式都刨析到底.废话不多说,开始第一种设计模式 - 单例. 作者已知的单例模式有8种写法,而每一种写法,都有自身的优缺点. 1,使用频率最高的写法,废话不多说,直接 ...

  7. PostgreSQL将日期转为当前年、月、日的函数date_trunc

    PostgreSQL将日期转为年.月.日的函数date_trunc: 当前年: select  date_trunc('year',now()) 当前月: select  date_trunc('mo ...

  8. 解决MySql客户端秒退(找不到my.ini)

    问题说明(环境:windows7,MySql8.0) 今天安装好MySql后启动MySql服务-->启动服务都失败的就不要往下看了,自行百度解决. 打开客户端秒退,但在cmd中是可以使用数据库的 ...

  9. 关于使用kms时遇到的there is nothing to do here

    我讲一下我自己的解决方法 ------------------------------------ 这个错误还是很明显的,没事干,如果不是kms的锅的话,那么就是字面上的问题了 ----------- ...

  10. AB实验人群定向HTE模型5 - Meta Learner

    Meta Learner和之前介绍的Casual Tree直接估计模型不同,属于间接估计模型的一种.它并不直接对treatment effect进行建模,而是通过对response effect(ta ...