Educational Codeforces Round 79 (Rated for Div. 2) Finished (A-D)
如果最大值比剩余两个加起来的总和+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)的更多相关文章
- Educational Codeforces Round 81 (Rated for Div. 2)E(线段树)
预处理把左集划分为大小为1~i-1时,把全部元素都移动到右集的代价,记作sum[i]. 然后枚举终态时左集的大小,更新把元素i 留在/移动到 左集的代价. 树状数组/线段树处理区间修改/区间查询 #d ...
- Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)
这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...
- Educational Codeforces Round 79 (Rated for Div. 2) - D. Santa's Bot(数论)
题意:有$n$个孩子,第$i$个孩子有$k[i]$件想要的礼物,第$j$个礼物为$a[i][j]$,现在随机挑一个孩子,从他想要的礼物里面随机挑一个,然后送给另一个孩子$($这个孩子可以和第一个孩子是 ...
- 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 ...
- 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 ...
- 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() ...
- 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 ...
- 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] ...
- 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 ...
随机推荐
- SpringBoot之ApplicationRunner接口和@Order注解
我们在开发中可能会有这样的情景.需要在容器启动的时候执行一些内容.比如读取配置文件,数据库连接之类的.SpringBoot给我们提供了ApplicationRunner接口来帮助我们实现这种需求.该接 ...
- MySQL8.0 InnoDB并行执行
概述 MySQL经过多年的发展已然成为最流行的数据库,广泛用于互联网行业,并逐步向各个传统行业渗透.之所以流行,一方面是其优秀的高并发事务处理的能力,另一方面也得益于MySQL丰富的生态.MySQL在 ...
- JAVA System.exit(0) 和 System.exit(1) 的区别
System.exit(int state) 方法都是来结束当前运行的java虚拟机.所有System.exit(1).System.exit(0) 执行后都会退出程序. state为0时时正常退出, ...
- 2019SACC中国系统架构师大会 day1总结
早上:一. 爱奇艺的大数据中台战略: a) 介绍爱奇艺的产业文化.b) 通过大中台,可以进行部分数据的沉淀,用于后续的分析处理等等.. 从数据中台和业务中台,建立一种“苹果园“的生态系统.从原始的长视 ...
- centos6.5下编译安装单实例MySQL5.5
MySQL5.5版本安装3步曲: 1) cmake 2) make 3) make install 查看系统版本号 [root@meinv01 ~]# cat /etc/redhat-release ...
- VMware vCenter Server6.5安装及群集配置介绍
借助 VMware vCenterServer,可从单个控制台统一管理数据中心的所有主机和虚拟机,该控制台聚合了集群.主机和虚拟机的性能监控功能. VMware vCenterServer 使管理员能 ...
- np.vstack与np.hstack
转自:https://zhuanlan.zhihu.com/p/82996332 留作备忘
- MySql存储引擎:innodb myisan memory
一.MySQL存在的常用存储引擎 存储引擎就是指表的类型,数据库的存储引擎决定了表在计算机中的存储方式. 使用show engines; (show engines\G;)可查看数据库支持的存储引擎 ...
- jq模糊匹配(qq:2798641729)
图灵学院--Java高级架构师-互联网企业级实战VIP课程(价值6380)(qq:1324981084) jq是一般程序员在前台开发的时候都会使用的技术,其中模糊匹配查询在动态添加标签的时候经常用到, ...
- hadoop3自学入门笔记(1)——虚拟机安装和网络配置
前言 年过30惶惶不安,又逢疫情,还是不断学习,强化自己的能力.hadoop的视频和书籍在15年的时候就看过,但是一直没动手实践过,要知道技术不经过实战,一点提升也没有.因此下定决心边学边做,希望能有 ...