CF Round#436 div2
额,这次的题目其实挺智障的。所以通过这次比赛,我也发现了自己是一个智障。。。。
不说太多,说多是泪。。。
A. Fair Game
题意:给你一个数组,看你能否把它均分为两个所有元素均相同的子数组。
模拟即可。。。。
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100+10
int n,c[MAXN],a=,b=;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
c[x]++;
if(!a)a=x;
else if(x!=a)b=x;
}
if(c[a]==c[b]&&c[a]+c[b]==n)printf("YES\n%d %d",a,b);
else printf("NO");
return ;
}
B. Polycarp and Letters
题意:给你一个字符串,请你找出一个满足如下要求的子序列:
1.子序列由不同的小写字母组成。
2.子序列中两个相邻的小写字母在原串的位置之间不得夹杂着大写字母
贪心地选就行了
#include<bits/stdc++.h>
using namespace std;
#define MAXN 210
int n,ans=,cnt[];
char s[MAXN];
bool judge(char c){return (c>='a'&&c<='z');}
int main(){
scanf("%d",&n);
scanf("%s",s);
int len=;
for(int i=;i<=n;i++){
if(i!=n&&judge(s[i])){
if(!cnt[s[i]-'a'])cnt[s[i]-'a']++,len++;
}
else{ans=max(ans,len);len=;memset(cnt,,sizeof(cnt));}
}
printf("%d",ans);
return ;
}
C. Bus
题意:一趟巴士在a公里的直线上来回穿梭k次(来去各算一次),巴士的油箱容量为b升,每走1公里耗费1升油,在f公里处有一个加油站,请问至少要加几次油?
额,能不加油就不加,实在跑不动了就加一次。如此往复贪心即可。(智障的我调了一个半小时才发现自己有一句话只打了前半句。。。)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ans=,a,b,f,k,oil;
int main(){
scanf("%I64d%I64d%I64d%I64d",&a,&b,&f,&k);
oil=b;
if(b<f||b<a-f){printf("-1");return ;}
for(int i=;i<=*k;i++){
if(i%==||i%==){
if(i&){
if(oil<f){printf("-1");return ;}
oil-=f;
}
else {
if(i==*k){
if(oil<a-f)ans++;
break;
}
else{
if(b<*(a-f)){printf("-1");return ;}
if(oil<*(a-f))ans++,oil=b;
oil-=(a-f);
}
}
}
else{
if(i&){
if(oil<a-f){printf("-1)");return ;}
oil-=(a-f);
}
else{
if(i==*k){
if(oil<f)ans++;
break;
}
else{
if(b<*f){printf("-1");return ;}
if(oil<*f)ans++,oil=b;
oil-=f;
}
}
}
}
printf("%I64d",ans);
return ;
}
D. Make a Permutation!
题意:给你一个由小于n的正整数组成的数组,问你至少得替换多少个元素才能使它成为一个全排列,并输出替换次数最少时字典序最小的全排列
明显贪心。。。。(只要你不把一些小学生都会的东西写反就行了)
#include<bits/stdc++.h>
using namespace std;
#define MAXN 200000+10
int n,a[MAXN],cnt[MAXN],st[MAXN],vis[MAXN],top=;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]),cnt[a[i]]++;
for(int i=;i<=n;i++)
if(!cnt[i])st[++top]=i;
int p=;
for(int i=;i<=n;i++){
if(p>top)break;
int x=st[p];
if(!vis[x]&&!cnt[x]){
if(a[i]>x&&cnt[a[i]]!=){
cnt[a[i]]--;
a[i]=x;
vis[x]=;
cnt[x]++;
p++;
}
else if(a[i]<=x){
if(!vis[a[i]])vis[a[i]]=;
else{
cnt[a[i]]--;
a[i]=x;
vis[x]=;
cnt[x]++;
p++;
}
}
}
}
printf("%d\n",top);
for(int i=;i<=n;i++)printf("%d ",a[i]);
return ;
}
E. Fire
题意:Polycarp家的房子着火了。在他的家中有n件物品,第i件价值为pi,抢救它所用的时间为ti,且只能在di时间之前抢救。问救出哪几件物品能使抢救的价值最大?
经典的排序背包问题,对di进行排序之后跑一遍背包并记录路径即可。
#include<bits/stdc++.h>
using namespace std;
#define MAXN 110
struct item{int t,d,p,id;}a[MAXN];
int n,last,top=,dp[MAXN][],ch[MAXN][],picked[];
bool cmp(item a,item b){return a.d<b.d;}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d%d",&a[i].t,&a[i].d,&a[i].p),a[i].id=i;
sort(a+,a+n+,cmp);
for(int i=;i<=n;i++){
last=;
for(int j=;j<=;j++){
if(j<a[i].d&&j>=a[i].t&&dp[i-][j-a[i].t]+a[i].p>=dp[i-][j]){
dp[i][j]=dp[i-][j-a[i].t]+a[i].p;
ch[i][j]=;
}
else dp[i][j]=dp[i-][j];
if(dp[i][j]>=dp[i][last])last=j;
}
}
printf("%d\n",dp[n][last]);
for(int i=n;i;i--)
if(ch[i][last]){
picked[++top]=a[i].id;
last-=a[i].t;
}
printf("%d\n",top);
for(int i=top;i;i--)printf("%d ",picked[i]);
return ;
}
CF Round#436 div2的更多相关文章
- CF Round #580(div2)题解报告
CF Round #580(div2)题解报告 T1 T2 水题,不管 T3 构造题,证明大约感性理解一下 我们想既然存在解 \(|a[n + i] - a[i]| = 1\) 这是必须要满足的 既然 ...
- CF round #622 (div2)
CF Round 622 div2 A.简单模拟 B.数学 题意: 某人A参加一个比赛,共n人参加,有两轮,给定这两轮的名次x,y,总排名记为两轮排名和x+y,此值越小名次越前,并且对于与A同分者而言 ...
- [CF Round #295 div2] C. DNA Alignment 【观察与思考0.0】
题目链接:C. DNA Alignment 题目大意就不写了,因为叙述会比较麻烦..还是直接看英文题面吧. 题目分析 经过观察与思考,可以发现,构造的串 T 的每一个字符都与给定串 S 的每一个字符匹 ...
- [CF Round #294 div2] E. A and B and Lecture Rooms 【树上倍增】
题目链接:E. A and B and Lecture Rooms 题目大意 给定一颗节点数10^5的树,有10^5个询问,每次询问树上到xi, yi这两个点距离相等的点有多少个. 题目分析 若 x= ...
- [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】
题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...
- A. Grasshopper And the String(CF ROUND 378 DIV2)
A. Grasshopper And the String time limit per test 1 second memory limit per test 256 megabytes input ...
- A. Alyona and Numbers(CF ROUND 358 DIV2)
A. Alyona and Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 【codeforces】【比赛题解】#864 CF Round #436 (Div.2)
做出了4题,还不错,可惜还是掉rating……能保持在蓝名已经不错了. 题目跳转链接. [A]公平的游戏 题意: Petya和Vasya在玩游戏.他们有n张卡片(n是偶数).每张卡片上有一个整数. 游 ...
- CF Round #569 Div2(contest1180)
比赛链接:http://codeforces.com/contest/1180 Problem A 题意:给出n,问方块数.看图理解... Solution: 找一找规律就可以了,发现方块数为2n*( ...
随机推荐
- 安装jdk时出现java -version权限不够问题
今天在ubuntu上安装jdk的时候,最后测试java -version总是不行,出现了 bash: /home/jdk1.7.0_25/bin/java: 权限不够的问题 百度之后,在http:// ...
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest J Cleaner Robot
Cleaner RobotCrawling in process... Crawling failed Time Limit:2000MS Memory Limit:524288KB ...
- Windows下caffe的python接口配置
主要是因为,发现很多代码是用python编写的,在这里使用的python安装包是anaconda2. 对应下载地址为: https://www.continuum.io/downloads/ 安装py ...
- Jenkins TFS配置
1. 在Jenkins中安装TFS插件 2. 在Build Server上安装tfs客户端程序,用来访问代码服务器获取代码, 这一部是由TFS Anywhere完成的 下载TFS Anywhere h ...
- CSS3中的属性介绍
概念:给文字添加阴影 语法:text-shadow: length length length color 介绍:前两个参数为阴影离开文字的横方向位移距离与纵方向位移距离.使用时前两个参数必须指定,也 ...
- 一起写框架-Ioc内核容器的实现-基础功能-ComponentScan支持组件注解限制(七)
实现功能 以上的代码我们发现.我们都是将@ComponentScan扫描的路径下的所有类都加载到容器中的. 而实际需求,我们并不希望所有的类都创建对象,而是加了组件注解@Controller,@Ser ...
- ace_tree总结。各类问题解决办法汇集
首先讲一下怎么使用,然后讲一下出现的问题的解决办法 1.引用js和css文件 ace-extra.min.js.ace.min.css.fuelux.tree.min.js.ace-elements. ...
- C#实现DirectShow技术开发准备
DirectShow组件在“C:\WINDOWS\system32”目录下的Quartz.dll动态库中,要使C#代码引用COM对象和接口,必须将COM类型库转换为.NET框架元数据,从而有效地创建一 ...
- 《天书夜读:从汇编语言到windows内核编程》十 线程与事件
1)驱动中使用到的线程是系统线程,在system进程中.创建线程API函数:PsCreateSystemThread:结束线程(线程内自行调用)API函数:PsTerminateSystemThrea ...
- asp.net web api客户端调用
服务接口 接口1: //Post:http://127.0.0.1/HY_WebApi/api/V2/Key/FunctionTest1 [HttpPost] public HttpResponseM ...