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 ...
随机推荐
- linux的su和sudo(转载)
来源:http://www.jb51.net/LINUXjishu/12713.html 一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比 ...
- 自译Solr in action中文版
文件夹 Part 1 初识 SOLR 1 Solr 简单介绍 2 開始熟悉 Solr 3 Solr 核心概念 4 配置 Solr 5 建立索引 6 文本分析 Part 2 Solr 核心功能 7 发起 ...
- 解决对象不支持“getElementsByClassName”属性或方法 ie兼容性
解决 IE 或者兼容模式不支持 document.getElementsByClassName() 的方法 自已实现document.getElementsByClassName(): 网页错 ...
- c#4.5新语法--自动属性和隐式类型
1.自动属性 自动属性是c#中属性定义的两种形式的一种:传统属性定义.自动属性. 1.1 传统属性定义 private int _age; public int ...
- Qt笔记之使用设计器自定义窗口标题栏
1.在窗口显示之前,设置WindowFlags为FramelessWindowHint,以产生一个没有边界的窗口 例如 Widget::Widget(QWidget *parent) : QWidge ...
- s1考试 图书管理系统 结构体版
#include <iostream> #include <string> #include <cstdio> #include <cstdlib> # ...
- Mongoose学习(3)--设置环境变量
比如我一套代码数据库代码分为中文站和英文站,每个表中我都有一个site_code字段来区分, 两个站点部署在不同的人服务器,这个时候我们就用系统环境变量来区分, 下面直接在mac下设置环境变量 vim ...
- assign,copy,strong,weak,nonatomic的具体理解
例子: NSString *houseOfMM = [[NSString alloc] initWithString:'MM的三室两厅']; 上面一段代码会执行以下两个动作: 1 在堆上分配一段内存 ...
- 浅淡!important对CSS的重要性
SS中的!important是一个非常重要的属性,有时候发挥着非常大的作用,52CSS.com这方面的知识并不是非常多,我们看下面的文章,对它作比较感观的了解. 前几天写一些CSS代码的时候又难为我了 ...
- LR添加Windows和Linux压力机实战
添加Windows和Linux压力机实战 既然Controller是LoadRunner的“心脏”,那么压力产生也必然是它发起的,通过压力机来对被测系统产生压力.一般压力机分为Windows和Linu ...