CF-Educational Codeforces Round 77 (Rated for Div. 2)(A-E题解)
A. Heating (水题)
大致思路:
因为是代价是平方,所以让每一个房间的大小平均即可,即最大和最小相差不超过一。
代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	ll c,sum;
	scanf("%lld",&n);
	while(n--){
		scanf("%lld%lld",&c,&sum);
		ll s=sum/c,yu=sum%c,ans=0;
		//cout<<s<<" "<<yu<<endl;
		for(int i=1;i<=min(c,sum);i++){
			if(yu){
				ans+=(s+1)*(s+1);yu--;
			}else{
				ans+=(s)*(s);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
B. Obtain Two Zeroes (找结论)
大致思路:
首先观察到 \((0,0)\) 态是可行的,那么其可以转移到的状态也是可行的,由于是加上 \(,x,2x\) ,那么 \((a,b)\) 的 \(a+b\) 必然是 \(3\) 的倍数,而且可以知道较大数不能大于较小的数两倍,虽然这只是必要条件,还是不够严谨,但是能过。
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	int n,a,b;
	scanf("%d",&n);
	while(n--){
		scanf("%d%d",&a,&b);
		if((a+b)%3==0&&max(a,b)<=2*min(a,b)){
			puts("YES");
		}
		else puts("NO");
	}
	return 0;
}
C. Infinite Fence (数学)
大致思路:
假设 \(r>b\) ,主要是判断在 \((m1*r,(m1+1)*r)\) 之中b的倍数最多出现多次。所以要找到一个 \(m*b\%r\) 的最小值,可以知道这个值就是 \(gcd(b,r)\) ,那么我们其实就是判断 \(gcd(b,r)+(k-1)*b\) 和 \(r\) 的关系就行了。
代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll gcd(ll a,ll b){
	return b==0?a:gcd(b,a%b);
}
ll T,r,b,k;
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	scanf("%lld",&T);
	while(T--){
		scanf("%lld%lld%lld",&r,&b,&k);
		if(r==b){ // 特判一个相等的情况,不够其实不用好像
			puts("OBEY");continue;
		}
		if(r<b)swap(r,b);
		if(r%b==0){
			if(k*b<r){
				puts("REBEL");
			}else puts("OBEY");
			continue;
		}
		ll g=gcd(r,b);
		if(g+(k-1)*b<r){
			puts("REBEL");
		}else puts("OBEY");
	}
	return 0;
}
D. A Game with Traps (二分+贪心)
大致思路:
首先最容易想的二分带的人数,然后进行判断,重点是怎么判断。发现无论如何部队必然要走 \(n+1\)步,那么我们可以不用去管,那么对于两个雷 \((l_1,r_1),(l_2,r_2)\), 如果 \(l_2<=r_1\) ,那么最优的方法就是一次性走到 \(r_2\) 再回来带人,否则就正常模拟。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
int n,m,k,t;
struct node{
	int l,r,d;
	node(int a=0,int b=0,int c=0){l=a,r=b,d=c;}
}lei[N];
vector<node>tt;
bool cmp(node a,node b){
	return a.l<b.l;
}
bool check(int x){
	tt.clear();
	int nl=a[x];
	for(int i=1;i<=k;i++)if(lei[i].d>nl)tt.push_back(lei[i]);//有危险的雷
	if(tt.size()==0)return 1;
	int ans=n+1,mx=0,now=tt[0].l-1;//部队行动距离必然要为n+1
	for(int i=0;i<int(tt.size());i++){
		mx=tt[i].r;
		int j=i+1;
		while(j<int(tt.size())&&tt[j].l<=mx)mx=max(mx,tt[j].r),j++;//有交集
		ans+=(mx-now)*2;
		now=tt[j].l-1;//更新
		i=j-1;
	}
	//cout<<x<<" "<<ans<<endl;
	if(ans<=t)return 1;//比较
	else return 0;
}
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	scanf("%d%d%d%d",&m,&n,&k,&t);
	for(int i=1;i<=m;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+m);//按能力排序
	reverse(a+1,a+1+m);//降序
	for(int i=1;i<=k;i++){
		scanf("%d%d%d",&lei[i].l,&lei[i].r,&lei[i].d);
	}
	sort(lei+1,lei+1+k,cmp);//按l排序
	int ans=0,l=1,r=m;
	while(l<=r){//二分
		int mid=(l+r)/2;
		if(check(mid)){
			ans=mid;l=mid+1;
		}else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}
E. Tournament (贪心)
大致思路:
我们发现每一轮都会淘汰一些人,我们的贪心策略就是让力量大的人尽量淘汰更多的人,那么我们就可以减少花费,而且在 \(k\) 轮,对于前 \(2^k-1\) 个人我们就不能选择,因为他们必定淘汰,所以我们从后面开始,每次选择我们可以选择的人花费最小的就行。
代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=(1<<20);
int n;
int a[N];
int vis[N];
multiset<int>s;
int main()
{
/*	freopen("H:\\c++1\\in.txt","r",stdin);
	freopen("H:\\c++1\\out.txt","w",stdout);
*/	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=0;(1<<i)<=n;i++)vis[(1<<i)]=1;
	ll ans=0;
	for(int i=n;i>=1;i--){
		if(a[i]==-1)break;
		s.insert(a[i]);
		if(vis[i]){//选择可以选的代价最小的人
			ans+=*(s.begin());
			s.erase(s.begin());
		}
	}
	printf("%lld\n",ans);
	return 0;
}
												
											CF-Educational Codeforces Round 77 (Rated for Div. 2)(A-E题解)的更多相关文章
- 【cf比赛记录】Educational Codeforces Round 77 (Rated for Div. 2)
		
比赛传送门 这场题目前三题看得挺舒服的,没有臃肿的题目,对于我这种英语渣渣就非常友好,但因为太急了,wa了两发A后才意识到用模拟(可以删了,博主真的是个菜鸟),结果导致心态大崩 ---- 而且也跟最近 ...
 - Educational Codeforces Round 77 (Rated for Div. 2) D A game with traps
		
题意:x正轴上有着一个陷阱的位置,开关和灵敏度,如果一个士兵灵敏度输给陷阱,他是过不去这个陷阱的幸运的是,你可以先过去把开关给关了,没错你是不怕陷阱的接下来呢你有操作,你移动一个,耗费一秒而你的团队需 ...
 - Educational Codeforces Round 77 (Rated for Div. 2)
		
A: 尽可能平均然后剩下的平摊 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int ...
 - Codeforce |Educational Codeforces Round 77 (Rated for Div. 2)  B. Obtain Two Zeroes
		
B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...
 - Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)
		
这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...
 - Educational Codeforces Round 77 (Rated for Div. 2) - D. A Game with Traps(二分)
		
题意:$m$个士兵,每个士兵都有一个灵敏度$a[i]$,起点为$0$,终点为$n + 1$,在路上有$k$个陷阱,每个陷阱有三个属性$l[i],r[i],d[i]$,$l[i]$表示陷阱的位置,如果你 ...
 - Educational Codeforces Round 77 (Rated for Div. 2)  C. Infinite Fence
		
C. Infinite Fence 题目大意:给板子涂色,首先板子是顺序的,然后可以涂两种颜色,如果是r的倍数涂成红色,是b的倍数涂成蓝色, 连续的k个相同的颜色则不能完成任务,能完成任务则输出OBE ...
 - Educational Codeforces Round 61 (Rated for Div. 2) D,F题解
		
D. Stressful Training 题目链接:https://codeforces.com/contest/1132/problem/D 题意: 有n台电脑,每台电脑都有初始电量ai,也有一个 ...
 - Educational Codeforces Round 81 (Rated for Div. 2) A-E简要题解
		
链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC ...
 - Educational Codeforces Round 65 (Rated for Div. 2)题解
		
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
 
随机推荐
- 利用python爬虫爬取图片并且制作马赛克拼图
			
想在妹子生日送妹子一张用零食(或者食物类好看的图片)拼成的马赛克拼图,因此探索了一番= =. 首先需要一个软件来制作马赛克拼图,这里使用Foto-Mosaik-Edda(网上也有在线制作的网站,但是我 ...
 - 云服务器搭建JDK+Tomcat+MySQL环境
			
一.首先租赁一台云服务器(阿里云服务器或者腾讯云服务器) 其实可以在windows电脑上使用VMware workstation来安装虚拟机进行操作,毕竟云服务器低配也是很贵的.不过可以使用学生价去租 ...
 - 微服务看门神-Zuul
			
Zuul网关和基本应用场景 构建微服务时,常见的问题是为系统的客户端应用程序提供唯一的网关. 事实上,您的服务被拆分为小型微服务应用程序,这些应用程序应该对用户不可见,否则可能会导致大量的开发/维护工 ...
 - 11 JavaScript Utility Libraries you Should Know in 2019
			
11 Useful Javascript utility libraries to speed your development.
 - The Five Qualities You Need in a Partner
			
The Five Qualities You Need in a Partner Things I Never Considered Before Getting Married (But Shoul ...
 - Centos7下把python 2.7升级到python 3.6(升级过程遇到的一些相关问题)
			
Centos 7 默认安装的Python 的版本是2.7的,现在不少人用的是3.x上的版本,故而需要了解下如何从Python2.7升级到Python 3.6. 在虚拟机安装时,网络不通会先遇到一个错误 ...
 - Linux下的sleep()和sched_yield()(转)
			
阿里四面被问到了这个问题,一脸懵逼,下来也没找到什么阐述这个的文章,就自己查man来对比总结一下吧: sched_yield()的man手册描述如下: DESCRIPTION sched_ ...
 - iOS项目运行出现:[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object
			
说白了就是 字典初始化 的时候 放入空的值了 下面这个比较具体 错误原因: NSDictionary *dic = @{@"key":value}这个初始化方法,发现keys co ...
 - Spring boot与Spring cloud之间的关系
			
Spring boot 是 Spring 的一套快速配置脚手架,可以基于spring boot 快速开发单个微服务,Spring Boot,看名字就知道是Spring的引导,就是用于启动Spring的 ...
 - 笔记-Git:资源列表
			
ylbtech-笔记-Git:资源列表 Yahoo!, Facebook, Salesforce, Microsoft, Twitter, Deutsche Telekom, Intuit, Mozi ...