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*( ...
随机推荐
- 用C写的计算运行时间
#include <stdio.h> #include <stdlib.h> #include <time.h> int main( void ) { long i ...
- Ionic3 创建应用(Android)
打开CMD 通过命令行进入项目目录 创建一个App项目 ionic start myApp blank 空白App ionic start myApp tabs 导航条 ionic start myA ...
- SSH服务详解
第1章 SSH服务 1.1 SSH服务协议说明 SSH 是 Secure Shell Protocol 的简写,由 IETF 网络工作小组(Network Working Group )制定:在进行数 ...
- transform 各种影响
1.提升元素的z-index层级,下面这个例子会让前面的图片显示在上面,一般来说应该是后面的覆盖前面图片的 <img src="mm1" style="-ms-tr ...
- 树莓派配置允许WINDOWS远程桌面 x11nvc+xrdp
20171109 网上很多设置教程都比较老旧,于是自己整理一下顺便分享下 开启SSH后,使用PUTTY连接. 安装x11vnc sudo apt-get install x11vnc 设置密码 sud ...
- URL模块之parse方法
url.parse(urlString , boolean , boolean) parse这个方法可以将一个url的字符串解析并返回一个url的对象. 参数: urlString指传入一个url地址 ...
- android wear开发之:建立可穿戴设备的应用 - Building Apps for Wearables
注:本文内容来自:https://developer.android.com/training/building-wearables.html 翻译水平有限,如有疏漏,欢迎批评指教. 译:山人 建立可 ...
- Excel、Exchange 和 C# (摘要)
Excel.Exchange 和 C#Eric GunnersonMicrosoft Corporation 2003年4月21日 摘要:Eric Gunnerson 将向您介绍如何使用 Outloo ...
- 【Java框架型项目从入门到装逼】第一节 - Spring框架 IOC的丧心病狂解说
大家好,好久不见,今天我们来一起学习一下关于Spring框架的IOC技术. 控制反转--Spring通过一种称作控制反转(IoC)的技术促进了松耦合.当应用了IoC,一个对象依赖的其它对象会通过被动的 ...
- 【爬虫】利用Scrapy抓取京东商品、豆瓣电影、技术问题
1.scrapy基本了解 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架.可以应用在包括数据挖掘, 信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取(更确切来说,网络抓 ...