Educational Codeforces Round 21 A-E题题解
A题 ............太水就不说了,贴下代码
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
using namespace std;
int n,m;
int main()
{
int i,j;
scanf("%d",&n);
int nn=n;
int cnt=;
while(nn>=)
{
nn/=;
cnt*=;
}
printf("%d\n",cnt*(nn+)-n);
}
B题 开始没看懂题什么意思(英语渣),然后看着样例找到了规律,就AC了
题意是计算上升和下降的序列数之和,再除以n-k+1即可,相当于求其中每k个数的和的平均值!
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
using namespace std;
int n,m,k;
double arr[];
double sum[];
int main()
{
int i,j;
scanf("%d%d",&n,&k);
for(i=;i<=n;i++)scanf("%lf",&arr[i]);
sum[]=;
for(i=;i<=n;i++)sum[i]=sum[i-]+arr[i];
double ans=;
for(i=;i+k<=n;i++)
{
ans+=sum[i+k]-sum[i];
}
ans/=((n-k+));
printf("%.10f\n",ans);
}
C 题 题目的意思是主人有n个茶杯,每个茶杯有容量。现在给一壶茶,总量为w。希望倒茶满足条件:每杯茶要超过容量的一半,并且w被倒光,茶杯内的茶水为整数,容量大的杯子内的茶不允许比容量小的杯子内的茶水少。
先给每个茶杯倒一半的水,然后把剩下的水尽量倒到容量大的茶杯里,倒完为止
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
using namespace std;
int n,m,w;
int arr[];
typedef struct node
{
int id,val,lim;
friend bool operator<(node a,node b){return a.lim<b.lim;}
}node;
node axx[];
int main()
{
int i,j;
scanf("%d%d",&n,&w);
int lim=;
for(i=;i<n;i++)
{
scanf("%d",&arr[i]);
lim+=(arr[i]+)/;
}
if(w<lim)printf("-1\n");
else
{
w-=lim;
for(i=;i<n;i++)axx[i].id=i,axx[i].val=(arr[i]+)/,axx[i].lim=arr[i];
sort(axx,axx+n);
for(i=n-;i>=&&w>;i--)while(axx[i].lim>axx[i].val&&w>)axx[i].val++,w--;
for(i=;i<n;i++)arr[axx[i].id]=axx[i].val;
for(i=;i<n;i++)
{
if(i)printf(" ");
printf("%d",arr[i]);
}
printf("\n");
}
}
D 题 给你一个序列ai,首先你可以让序列中的一个数移动到这个序列的任何一个位置,然后让你求是否存在一个前缀,使得前缀和等于序列中其余的数的和
解法:扫一遍求前缀和,扫x时有三种情况是yes,第一,1~x的前缀和恰好等于序列总和的一半;第二,存在前缀序列中某一个数跳到了后缀里,使得新的前缀和满足条件,
即(1~x+1前缀和-跳出去的数的值)=序列总和的一半;第三,存在后缀序列中某一个数跳到了前缀里,使得新的前缀和满足条件,即(1~x-1前缀和+跳进来的数的值)=序列总和的一半,
只要用map来维护前缀和后缀中存在的数即可
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
int n,m;
ll arr[];
ll sum[];
map<ll,int>dui1,dui2;
int main()
{
int i,j;
scanf("%d",&n);
for(i=;i<=n;i++)scanf("%I64d",&arr[i]);
dui1.clear();
dui2.clear();
sum[]=;
for(i=;i<=n;i++)sum[i]=sum[i-]+arr[i];
if(sum[n]&)
{
printf("NO\n");
}
else
{
for(i=;i<=n;i++)
{
if(!dui2.count(arr[i]))dui2[arr[i]]=;
else dui2[arr[i]]++;
}
for(i=;i<n;i++)
{
dui1[arr[i]]=;
dui2[arr[i]]--;
if(sum[i]==sum[n]/)
{
printf("YES\n");
return ;
}
else if(dui1.count(arr[i+]+sum[i]-sum[n]/))
{
printf("YES\n");
return ;
}
else if(dui2[-sum[i]+arr[i]+sum[n]/]>)
{
printf("YES\n");
return ;
}
}
printf("NO\n");
}
return ;
}
E题 题意是一个01背包,坏消息是n<=100000,m<=300000,好消息是w=1,2,3...这个题直接O(nm)去做肯定不行,模拟比赛的时候我心存侥幸大范围贪心,小范围dp,然后果断WA了....
正解是三分法,首先我们把物品以w=1,2,3分类,然后分别排序,并求出前缀和,然后枚举取用w=3的物品的个数,然后 三分2的个数, 1的个数也就知道了 。而2的个数和是一个单峰函数,
所以可以用三分法
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstdio>
#include<set>
using namespace std;
typedef long long ll;
vector<ll>arr[];
ll sum[][];
ll n,m;
bool cmp(ll a,ll b){return a>b;}
ll getans(ll tri,ll dob){return sum[][tri]+sum[][dob]+sum[][m-tri*-dob*];}
int main()
{
ll i,j;
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
ll w;
ll val;
scanf("%I64d%I64d",&w,&val);
arr[w].push_back(val);
}
for(i=;i<=;i++)sort(arr[i].begin(),arr[i].end(),cmp);
for(i=;i<=;i++)
{
sum[i][]=;
for(j=;j<=arr[i].size();j++)sum[i][j]=sum[i][j-]+arr[i][j-];
for(j=arr[i].size()+;j<=m;j++)sum[i][j]=sum[i][j-];
}
ll maxn=;
for(i=;i<=arr[].size();i++)
{
if(*i>m)break;
ll l=,r=(m-*i)/;
while(r-l>)
{
ll rmid=(r*+l)/;
ll lmid=(l*+r)/;
ll ans1=getans(i,lmid);
ll ans2=getans(i,rmid);
if(ans1>ans2)r=rmid;
else l=lmid;
maxn=max(maxn,ans1);
maxn=max(maxn,ans2);
}
for(j=l;j<=r;j++)maxn=max(getans(i,j),maxn);
//printf("%I64d\n",maxn);
}
printf("%I64d\n",maxn);
return ;
}
Educational Codeforces Round 21 A-E题题解的更多相关文章
- Educational Codeforces Round 21
Educational Codeforces Round 21 A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...
- Educational Codeforces Round 21 Problem D(Codeforces 808D)
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...
- Educational Codeforces Round 21 Problem A - C
Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...
- Educational Codeforces Round 37-F.SUM and REPLACE题解
一.题目 二.题目链接 http://codeforces.com/contest/920/problem/F 三.题意 给定$N$个范围在$[1, 1e6)$的数字和$M$个操作.操作有两种类型: ...
- Educational Codeforces Round 21 D.Array Division(二分)
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)
A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...
- Educational Codeforces Round 37-G.List Of Integers题解
一.题目 二.题目链接 http://codeforces.com/contest/920/problem/G 三.题意 给定一个$t$,表示有t次查询.每次查询给定一个$x$, $p$, $k$,需 ...
- CF Educational Codeforces Round 21
A. Lucky Year time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- org.hibernate.LazyInitializationException...no session or session was closed
org.hibernate.LazyInitializationException:failed to lazily initialize a collection of role:cn.its.oa ...
- GoodReads: Machine Learning (Part 3)
In the first installment of this series, we scraped reviews from Goodreads. In thesecond one, we per ...
- [rctf](web)rcdn 解题分析,知识点总结
比赛平台关闭了,没有截图,见谅. 解题思路流程: 分析网站结构,看源码,元素审计.发现以下信息. 要得到flag要获得一个pro cdn pro 子域名长度为3到6个字符 存在一个提交ticke页 ...
- vue2.0+element+node+webpack搭建的一个简单的后台管理界面
闲聊: 今天是六一儿童节哟,小颖祝大家节日快乐哈哈哈.其实这个demo小颖断断续续做了将近两个礼拜了,心塞的,其实这个也没有多难,主要是小颖有点最近事情有点多,所以就把这个一直拖着,今天好不容易做好了 ...
- C语言错题小本子
int a; ; a = ! x< //a的值是多少 我的答案:0, 正确答案:1 错误原因:没有熟练掌握运算符的优先级 // 找出下面无效的C语言变量名 A. _a B. main C. pr ...
- php系统共享模板问题
我们在用php+html+css来写一个管理系统时,例如报名系统.投票系统,统计系统等,我们往往需要在管理后台查看每一位报名者的情况,问题接着就来了,由于比赛或者活动要求不同个,往往报名表不太一样,这 ...
- HashMap集合
HashMap集合特点(用法与特点类似于HashSet集合): 1.无序,不允许重复(无序指元素顺序与添加顺序不一致): 2.底层数据结构是哈希表 3.HashMap内部对"键"用 ...
- Ch.3 Aray and String
3-1 scrore Here is a string with o and x. The length is between 1 to 80. Calcuate the score. The sc ...
- Java经典编程题50道之三十三
打印出杨辉三角形(要求打印出10行如下图)11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1 public class Example33 { public static v ...
- Java语言编程注意事项
1.大小写敏感,要注意区分大小写: 2.一般每一句代码写完之后,后面以":"结尾: 3.在代码中,括号的出现一般都是成对的,如:{}.