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题题解的更多相关文章

  1. Educational Codeforces Round 21

    Educational Codeforces Round 21  A. Lucky Year 个位数直接输出\(1\) 否则,假设\(n\)十进制最高位的值为\(s\),答案就是\(s-(n\mod ...

  2. 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 ...

  3. Educational Codeforces Round 21 Problem A - C

    Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...

  4. Educational Codeforces Round 37-F.SUM and REPLACE题解

    一.题目 二.题目链接 http://codeforces.com/contest/920/problem/F 三.题意 给定$N$个范围在$[1, 1e6)$的数字和$M$个操作.操作有两种类型: ...

  5. 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 ...

  6. 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 ...

  7. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  8. Educational Codeforces Round 37-G.List Of Integers题解

    一.题目 二.题目链接 http://codeforces.com/contest/920/problem/G 三.题意 给定一个$t$,表示有t次查询.每次查询给定一个$x$, $p$, $k$,需 ...

  9. CF Educational Codeforces Round 21

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

随机推荐

  1. 关于Cookie安全性设置的那些事

    一.标题:关于Cookie安全性设置的那些事 副标:httponly属性和secure属性解析 二.引言 经常有看到XSS跨站脚本攻击窃取cookie案例,修复方案是有httponly.今天写出来倒腾 ...

  2. Spring Mvc 用Demo去学习

    1:首先大体知道 SpringMVC 框架的 运行原理(图片来自网络 ) 2:SpringMVC 是依照DispatcherServlet 展开的 这里可以约Structs2对比,structs2 是 ...

  3. More 3D Graphics (rgl) for Classification with Local Logistic Regression and Kernel Density Estimates (from The Elements of Statistical Learning)(转)

    This post builds on a previous post, but can be read and understood independently. As part of my cou ...

  4. 2016计蒜之道复赛B题:联想专卖店促销

    题解 思路: 二分答案,设我们要check的值为x. 注意到每一个礼包都有,一个U盘,一个鼠标. 剩余的,分别为一个机械键盘,一个U盘,一个鼠标. 当礼包数目为x时,我们至多可以提供a-x个普通,b- ...

  5. 两强相争,鹿死谁手 — JQuery中的Ajax与AngularJS中的$http

    一.JQuery与AngularJS 首先,先简单的了解一下JQuery与AngularJS.从源头上来说,两者都属于原生JS所封装成的库,两种为平行关系. 二.Ajax请求与数据遍历打印 这里是Aj ...

  6. IPv6启动五年后,距离我们究竟还有多远?

    作者:RicardoIPv6拥有更好的IP拓展性,更高的安全保障以及更快的传输速度,互联网协会将2012年6月6日定为了世界IPv6启动日,距此5年后,国内外Cloudflare.又拍云等CDN服务已 ...

  7. NLTK学习笔记(三):NLTK的一些工具

    主要总结一下简单的工具:条件频率分布.正则表达式.词干提取器和归并器. 条件分布频率 <自然语言学习>很多地方都用到了条件分布频率,nltk提供了两种常用的接口:FreqDist 和 Co ...

  8. Hadoop hdfs完全分布式搭建教程

    1.安装环境 ①.四台Linux CentOS6.7 系统 hostname                ipaddress              subnet mask             ...

  9. linux tesseract 安装及部署tess4j项目的常见问题

    linux上部署tess4j项目 在windows上项目是可以正常运行的,部署到Linux上后,运行报异常,异常内容为:Unable to load library 'tesseract': Nati ...

  10. react 基础

    一.组件 函数式定义的无状态组件 es5原生方式React.createClass定义的组件 es6形式的extends React.Component定义的组件 React.Component是以E ...