Codeforces Round #377 (Div. 2)A,B,C,D【二分】
PS:这一场真的是上分场,只要手速快就行。然而在自己做的时候不用翻译软件,看题非常吃力非常慢,还有给队友讲D题如何判断的时候又犯了一个毛病,一定要心平气和,比赛也要保证,不要用翻译软件做题;
Codeforces732A
水题;
#include<cstdio>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7; int main()
{
int n,m;
scanf("%d%d",&n,&m);
int tmp;
for(int i=0;;i++)
{
tmp=i*10;
if(tmp%n==0&&tmp)
{
printf("%d\n",tmp/n);
return 0;
}
tmp+=m;
if(tmp%n==0)
{
printf("%d\n",tmp/n);
return 0;
}
}
}
Codeforces 732B.
Cormen — The Best Friend Of a Man
求一个最少数量,使得连续两个是>=k
保证b[i]>=a[i];
我肯定是加中间的,加中间的话两边都能利用,而且一定要加;
#include<cstdio>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7;
const int N=5e2+10;
int a[N];
int b[N]; int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int tmp,flag=0,ans=0;
b[1]=a[1];
for(int i=2;i<=n;i++)
{
tmp=b[i-1]+a[i];
if(tmp>=m)
b[i]=a[i];
else
{
b[i]=m-b[i-1];
ans+=b[i]-a[i];
}
}
printf("%d\n",ans);
for(int i=1;i<=n;i++)
{
if(i!=1) printf(" ");
printf("%d",b[i]);
}
return 0;
}
Codeforces 732C
- Sanatorium
最大和最小的数量<=1就一定能全部进行结束,所以求一个最大,保证和最大的差值<=1就好了;
#include<cstdio>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const int INF=0x3f3f3f3f;
const LL mod=1e9+7;
LL a[4];
int main()
{
LL mx;
scanf("%I64d",&a[1]);
mx=a[1];
for(int i=2;i<=3;i++)
{
scanf("%I64d",&a[i]);
mx=max(a[i],mx);
}
LL ans=0;
for(int i=1;i<=3;i++)
{
if(a[i]+1>=mx)
continue;
ans+=mx-1-a[i];
}
printf("%I64d\n",ans);
return 0;
}
Codeforces 732D
只要二分一个答案,然后判断满不满足就行了,判断的时候倒着判断,开了两个值代表需要准备的天数,已经准备的天数维护一下就好了;
#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std; const int N=1e5+10;
int a[N],w[N];
bool vis[N];
int m; bool Judge(int n)
{
int sum,x,y,num;
memset(vis,false,sizeof(vis));
x=y=num=0;
for(int i=n;i>=1;i--)
{
if(!a[i])
{
if(x>y)
y++;
}
else
{
if(vis[a[i]])
{
if(x>y)
y++;
}
else
{
num++;
x+=w[a[i]];
vis[a[i]]=true;
}
}
if(x==y&&num==m)
return true;
}
return false;
} int solve(int n)
{
int left=1,right=n;
while(left<right)
{
int mid=left+(right-left)/2;
if(Judge(mid))
right=mid;
else
left=mid+1;
}
return left;
} int main()
{
int n;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d",&w[i]);
if(!Judge(n))
{
puts("-1");
return 0;
}
int ans;
ans=solve(n);
printf("%d\n",ans);
return 0;
}
Codeforces Round #377 (Div. 2)A,B,C,D【二分】的更多相关文章
- Codeforces Round #377 (Div. 2) D. Exams
Codeforces Round #377 (Div. 2) D. Exams 题意:给你n个考试科目编号1~n以及他们所需要的复习时间ai;(复习时间不一定要连续的,可以分开,只要复习够ai天 ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- Codeforces Round #377 (Div. 2)
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...
- Codeforces Round #377 (Div. 2)D(二分)
题目链接:http://codeforces.com/contest/732/problem/D 题意: 在m天中要考k个课程, 数组a中有m个元素,表示第a[i]表示第i天可以进行哪门考试,若a[i ...
- Codeforces Round #377 (Div. 2) E. Sockets
http://codeforces.com/contest/732/problem/E 题目说得很清楚,每个电脑去插一个插座,然后要刚好的,电脑的power和sockets的值相同才行. 如果不同,还 ...
- Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
http://codeforces.com/contest/732/problem/D 这题我发现很多人用二分答案,但是是不用的. 我们统计一个数值all表示要准备考试的所有日子和.+m(这些时间用来 ...
- Codeforces Round #377 (Div. 2) 被坑了
http://codeforces.com/contest/732/problem/B 题目要求任意两个连续的日子都要 >= k 那么如果a[1] + a[2] < k,就要把a[2]加上 ...
- Codeforces Round #377 (Div. 2) B. Cormen — The Best Friend Of a Man(贪心)
传送门 Description Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has ...
- Codeforces Round #377 (Div. 2) D. Exams(二分答案)
D. Exams Problem Description: Vasiliy has an exam period which will continue for n days. He has to p ...
随机推荐
- javaScript中innerHTML,innerText,outerHTML,outerText的区别
开头说下innerText和outerText只在chrome浏览器中有效 定义和用法 innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML,包括标签. 来看代码 <!DOC ...
- 图像处理之图像增强项目---csdn去雾专栏1
(一)高斯低通滤波去噪 高斯低通滤波器(Gaussian Low Pass Filter)是一类传递函数为高斯函数的线性平滑滤波器.又由于高斯函数是正态分布的密度函数.因此高斯低通滤波器对于去除服从正 ...
- 在zend framework框架中try{}catch(Exception e){}的跳转问题
请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1 首先我先说明我遇到的问题 try{ //导入学生信息 $ModelStudent->insert($dat ...
- BZOJ 4316: 小C的独立集 仙人掌 + 树形DP
4316: 小C的独立集 Time Limit: 10 Sec Memory Limit: 128 MB Description 图论小王子小C经常虐菜,特别是在图论方面,经常把小D虐得很惨很惨. ...
- EasyDarwin做转发延时太大?
很多人反映,在用EasyDarwin做流媒体转发服务时,延时太大,实际Darwin在转发模块中,有一个控制转发Buffer时间的配置reflector_buffer_size_sec,我们将这个配置改 ...
- c# winform中预防窗体重复打开
当窗体以非模态形式打开的时候,有可能出现重复打开的情形,利用以下的代码可以预防重复打开! foreach (Form f in Application.OpenForms) { if (f.Nam ...
- A桶中有多少水?
如果你能算出桶中有多少水,我便许你下山去玩.有一天,老和尚让小和尚将A桶的水挑到B桶去,可是小和尚却想下山玩,不愿意挑水,老和尚便说:”如果你能够根据我的提示算出A桶中有多少升水,我便许你下山去玩.” ...
- python自动化运维九:Playbook
playbook:playbook 由一个或多个 ‘plays’ 组成.它的内容是一个以 ‘plays’ 为元素的列表.在 play 之中,一组机器被映射为定义好的角色.在 ansible 中,pla ...
- egret+git+阿里云code搭建团队开发
准备: GIT客户端 廖雪峰老师GIT教程 GIT客户端安装完成后,打开Git Bash ,输入代码 ,设置git提交与获取的git账户信息 git config --global user.name ...
- matlab从fig文件中提取数据
如果你的fig文件中图像是由多条曲线绘制而成,比如说plot命令生成的,通过以下方式输出横坐标,纵坐标的取值 open('figname.fig'); lh = findall(gca, 'type' ...