Round A 2020 - Kick Start 2020

Allocation

题意:n(1e5)个数,选出尽可能多的数使他们总和小于等于b。

思路:排序,尽可能取小。

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 #define dl double
 4 void rd(int &x){
 5  x=0;int f=1;char ch=getchar();
 6  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
 7  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
 8 }
 9 void lrd(LL &x){
10  x=0;int f=1;char ch=getchar();
11  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
12  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
13 }
14 const int INF=1e9;
15 const LL LINF=1e18;
16 const int N=1e5+10;
17 using namespace std;
18 int T,n,a[N],b;
19 int main(){
20 // freopen("in.txt","r",stdin);
21  rd(T);
22  for(int t=1;t<=T;t++){
23   rd(n);rd(b);
24   for(int i=1;i<=n;i++)rd(a[i]);
25   sort(a+1,a+n+1);int mx=0;
26   for(int i=1;i<=n;i++){
27    b-=a[i];
28    if(b >= 0)mx=i;
29    else break;
30   }
31   printf("Case #%d: %d\n",t,mx);
32  }
33  return 0;
34 }
35 /**/

Plates

题意:n(50)组数字,每组k(30)个,选出p个数,使得和最大,如果要选择一个数字就必须选择其所在组中它前面的所有数字。

思路:fij表示前i组,一共选了j个数最大值是多少,每个fij枚举当前组取前多少个数字更新答案。

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 #define dl double
 4 void rd(int &x){
 5  x=0;int f=1;char ch=getchar();
 6  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
 7  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
 8 }
 9 void lrd(LL &x){
10  x=0;int f=1;char ch=getchar();
11  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
12  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
13 }
14 const int INF=1e9;
15 const LL LINF=1e18;
16 const int N=55;
17 const int K=35;
18 using namespace std;
19 int T,n,k,p;
20 int f[N][N*K];
21 int a[N][K];
22 int main(){
23 // freopen("in.txt","r",stdin);
24  rd(T);
25  for(int t=1;t<=T;t++){
26   rd(n);rd(k);rd(p);
27   for(int i=1;i<=n;i++)
28    for(int j=1;j<=k;j++)
29     rd(a[i][j]);
30   memset(f,0,sizeof(f));
31   for(int i=0;i<n;i++){
32    int now=0;
33    for(int j=0;j<=k;j++){
34     now+=a[i+1][j];
35     int tmp=min(i*k,p);
36     for(int o=0;o<=tmp;o++)
37      f[i+1][o+j]=max(f[i+1][o+j],f[i][o]+now);
38    }
39   }
40   int mx=0;
41   for(int i=0;i<=p;i++)mx=max(mx,f[n][i]);
42   printf("Case #%d: %d\n",t,mx);
43  }
44  return 0;
45 }
46 /**/

Workout

题意:给n(1e5)个正整数,在其中插入k个正整数,使得相邻两数之差绝对值的最大值最小,输出这个值是多少。

思路:发现如果k个数可以做到,k+1个数也可以做到,具有单调性,不妨二分答案,判断过程记录每两个数之间至少插入数的个数。需要注意我的写法中二分部分对于判断0时会出现问题,所以二分下限设成了1,0的情况只能是所有数字都相同的情况,特殊判断即可。

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 #define dl double
 4 void rd(int &x){
 5  x=0;int f=1;char ch=getchar();
 6  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
 7  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
 8 }
 9 void lrd(LL &x){
10  x=0;int f=1;char ch=getchar();
11  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
12  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
13 }
14 const int INF=1e9;
15 const LL LINF=1e18;
16 const int N=1e5+10;
17 using namespace std;
18 int T;
19 int n,k,a[N];
20 bool check(int x){
21  int now=k;
22  for(int i=1;i<n;i++){
23   int tmp1=a[i+1]-a[i];
24   int tmp2=(tmp1+x-1)/x;
25   now-=tmp2-1;
26   if(now < 0)return 0;
27  }
28  return 1;
29 }
30 int main(){
31 // freopen("in.txt","r",stdin);
32  rd(T);
33  for(int t=1;t<=T;t++){
34   rd(n);rd(k);
35   for(int i=1;i<=n;i++)rd(a[i]);
36   int l=1,r=1e9;
37   while(l != r){
38    int mid=l+r>>1;
39    if(check(mid))r=mid;
40    else l=mid+1;
41   }
42   bool flg=0;
43   for(int i=1;i<n;i++)if(a[i]!=a[i+1])flg=1;
44   if(!flg)l=0;
45   printf("Case #%d: %d\n",t,l);
46  }
47  return 0;
48 }
49 /**/

Bundling

题意:n(1e5)个字符串,每k(n%k==0)个分为一组,每组权值为组内元素最大公共前缀的长度,求所有组权值和的最大值是多少。

思路:trie树上dfs,一旦当前点子树大小超过了k就将这k个分为一组,贪心即可。

 1 #include<bits/stdc++.h>
 2 #define LL long long
 3 #define dl double
 4 void rd(int &x){
 5  x=0;int f=1;char ch=getchar();
 6  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
 7  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
 8 }
 9 void lrd(LL &x){
10  x=0;int f=1;char ch=getchar();
11  while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
12  while(ch<=‘9‘ && ch>=‘0‘)x=x*10+ch-‘0‘,ch=getchar();x*=f;
13 }
14 const int INF=1e9;
15 const LL LINF=1e18;
16 const int N=1e5+10;
17 using namespace std;
18 int T,n,k,ans;
19 int ch[N*20][26],tot,siz[N*20],dep[N*20];
20 string s;
21 void clear(){
22  for(int i=0;i<=tot;i++){
23   siz[i]=0;dep[i]=0;
24   for(int j=0;j<26;j++)
25    ch[i][j]=0;
26  }
27  tot=0;ans=0;
28 }
29 void insert(string s){
30  int len=s.size(),now=0;
31  for(int i=0;i<len;i++){
32   if(!ch[now][s[i]-‘A‘])ch[now][s[i]-‘A‘]=++tot;
33   now=ch[now][s[i]-‘A‘];
34  }
35  siz[now]++;
36 }
37 void dfs(int x){
38  for(int i=0;i<26;i++){
39   if(!ch[x][i])continue;
40   dep[ch[x][i]]=dep[x]+1;
41   dfs(ch[x][i]);
42   siz[x]+=siz[ch[x][i]];
43   if(siz[x] >= k)ans+=dep[x]*(siz[x]/k),siz[x]%=k;
44  }
45  if(siz[x] >= k)ans+=dep[x]*(siz[x]/k),siz[x]%=k;
46 }
47 int main(){
48 // freopen("in.txt","r",stdin);
49  rd(T);
50  for(int t=1;t<=T;t++){
51   rd(n);rd(k);clear();
52   for(int i=1;i<=n;i++){
53    cin>>s;
54    insert(s);
55   }
56   dfs(0);
57   printf("Case #%d: %d\n",t,ans);
58  }
59  return 0;
60 }
61 /**/

原文地址:https://www.cnblogs.com/hyghb/p/12589843.html

时间: 2024-08-30 17:21:17

Round A 2020 - Kick Start 2020的相关文章

Google Kick Start 2020 Round A

Allocation 题意 N个房子出售,每个卖Ai刀,现有B刀资金,求最多买多少个. 思路 贪心,排序后从小到大买 代码 #include<bits/stdc++.h> using namespace std; const int MAX=1e5+5; int a[MAX]; int main() { int T,cas=0; scanf("%d",&T); while(T--) { int n,b,res=0; scanf("%d%d",&a

Round G 2019 - Kick Start 2019

https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050e02/000000000018fd0d Book Reading (10pts, 15pts) 1 ≤ T ≤ 100.1 ≤ P1 < P2 < ... < PM ≤ N.1 ≤ Ri ≤ N, for all i. Test set 1 (Visible) 1 ≤ M ≤ N ≤ 1000.1 ≤ Q ≤ 1000. Test set 2 (

2020.1.1~2020.1.5 阅读小结

一周阅读小结(1.1-1.5) 新的一年里尝试一种新的学习方法.考虑到工作日只能在碎片时间里看一些小篇幅的技术文章,但是经常看了就忘.这里尝试每周对一些印象深刻的文章做一次review,算是对知识的复习.有的文章经常只mark不看,也争取集中在周末消化掉,不要做个马来人:) 使用 Micrometer 记录 Java 应用性能指标 本文是为数不多中文博客里能把micrometer的概念和用法讲得比较清晰的,能够感受到作者的功底,看完去搜了下作者的名字,果然找到了很多精彩的文章. @EnableW

2020.1.6 ~ 2020.1.12 阅读小结

一周阅读总结(1.6-1.12) 本周主要在看Operation System:3 Easy Pieces,看了5章,不知为何虽然序言里推荐要先读完CSAPP,但是感觉本书比CSAPP简单 OSTEP: cpu-intro 介绍进程,CPU通过分时复用处理多进程,实现CPU资源的虚拟化 OSTEP: cpu-api 以shell交互为例,介绍UNIX系统fork(),wait(),exec()系列函数的使用,Java写多了,确实会感觉这些UNIX API不够友好 ,有时间写个文章总结下.作者还专

周记2020.3.2~2020.3.8

1. @PostConstruct和@PreConstruct @PostConstruct说明 被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Serclet的inti()方法.被@PostConstruct修饰的方法会在构造函数之后,init()方法之前运行. 特点: 1.只有非静态方法能使用此注解 2.被注解的方法不得有任何参数 3.被注解的方法返回值必须为void 4.被注解方法不得抛出已检查异常 5.此方法只会被执行一次

Google Kickstart 2020 Round A: Plates Solution

Problem Statement Problem Dr. Patel has N stacks of plates. Each stack contains K plates. Each plate has a positive beauty value, describing how beautiful it looks. Dr. Patel would like to take exactly P plates to use for dinner tonight. If he would

2020年AI、CV、NLP顶会最全时间表

2020年AI.CV.NLP顶会最全时间表 2019-09-01 14:04:19 weixin_38753768 阅读数 40 2020 AI.CV.NLP主流会议时间表,包含会议举办的时间.地点.投稿截止日期.官方网址/社交媒体地址,还有H指数(谷歌学术的期刊会议评判标准,即过去5年内有至多h篇论文被引用了至少h次). 2月 AAAI 2020 会议名称: Association for the Advancement of Artificial Intelligence 会议地点: New

智能家居展|2020年海峡国际智能家居展览会

518展|518展会|518展览会|2020年518展|2020年518展会|2020年518展览会|海交会|2020海交会|2020年海交会|第22届海交会|2020年第22届海交会|2020福建518海交会|2020年福建518海交会|智能家居展|智能家居展会|智能家居展览会|2020智能家居展|2020智能家居展会|2020智能家居展览会|2020年智能家居展|2020年智能家居展会|2020年智能家居展览会|福州智能家居展|福州智能家居展会|福州智能家居展览会|2020福州智能家居展|2

[2020 新春红包题]1

0x00 知识点 反序列化?构造pop链 改编自 2019全国大学生安全运维赛 EZPOP 0x01解题 题目给了我们源码 <?php error_reporting(0); class A { protected $store; protected $key; protected $expire; public function __construct($store, $key = 'flysystem', $expire = null) { $this->key = $key; $this