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*( ...
随机推荐
- 数据分析基础之Linalg的使用
Linear algebra 简介 When SciPy is built using the optimized ATLAS LAPACK and BLAS libraries, it has ve ...
- Python Web框架篇:Django Model基础
model是关于你的数据的单一的,确定的信息来源. 它包含您正在存储的数据的基本字段和行为.Django通过抽象化的模型层(models)为你的网络应用提供对于数据的结构化处理和操作处理,数据库相关的 ...
- Codeforces Round #386 (Div. 2) C. Tram
C. Tram time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- 离线缓存 manifest
程序的离线缓存由一个叫做manifest的文本文件控制,把需要离线缓存的文件列在里面即可,这个列表还可以控制需要缓存的情况,甚至当用户从缓存地址进入到没有缓存的地址应该显示什么 当浏览器下载解析了ma ...
- Spring AOP高级——源码实现(1)动态代理技术
在正式进入Spring AOP的源码实现前,我们需要准备一定的基础也就是面向切面编程的核心——动态代理. 动态代理实际上也是一种结构型的设计模式,JDK中已经为我们准备好了这种设计模式,不过这种JDK ...
- 修改oracle服务器端字符集
----设置字符集步聚------- conn /as sysdba; shutdown immediate; startup mount; alter system enable restricte ...
- 高阶函数,柯里化,sort排序
高阶函数概念 first class object: 函数在python中时一等公民. 函数也是对象,可调用的对象. 函数可以作为普通变量,参数,返回值等等. 高阶函数: ...
- CentOS系统中出现错误--SSH:connect to host centos-py port 22: Connection refused
我在第一次搭建自己的 hadoop2.2.0单节点的伪分布集成环境时遇到了此错误,通过思考问题和查找解决方案最终搞定了这个问题,其错误原因主要有以下几种: 1)SSH服务为安装 此时,采用在线安装的方 ...
- unity下跨平台excel读写
这是以前写的跨windows和ios读写excel的工具,因为原来导表工具引用的第三方读写excel的dll只能在windos下使用,造成要在mac机器上跑PC端或者打包的时候,每次都要先在windo ...
- C#多功能DataGridView打印类(WinForm)
; printPreviewDialog.ShowDialog(); } catch { ...