Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2)
敲出一身冷汗。。。感觉自己宛如智障:(
codeforces 864 A. Fair Game【水】
题意:已知n为偶数,有n张卡片,每张卡片上都写有一个数,两个人每人选一个数,每人可以拿的卡片必须写有是自己选的数,问能否选择两个数使得两个人每人拿的卡片数一样多并且能拿光卡片。[就是看输入是不是只有两种数字]
//:第一遍我看成字符串包含有选的数字也能拿,,这样写着居然过了。。水题水题。。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n, a[N];
int main() {
int i, k, x=, y=;
scanf("%d", &n);
for(i = ; i <= n; ++i){
scanf("%d", &k);a[k]++;
if(!x) x=k; else if(k!=x) y=k;
}
if(a[x]==a[y] && a[x]+a[y]==n){printf("YES\n%d %d\n", x, y);}
else puts("NO");
return ;
}
15ms
codeforces 864 B. Polycarp and Letters【水】
题意:给一个只包含大写字母和小写字母的字符串,现在有一个集合,它可以包含字符串中的不同小写字母的位置,但是要求其任意两个位置之间在字符串中不能有大写字母。求集合最大的大小。
题解:线性暴力扫过去,求每段大写字母之间包含的最多的不同小写字母数量。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
const int N=;
int n;
string s;
set<char>st;
int main() {
int i, j, k, m = ;
scanf("%d", &n);
cin >> s; s += 'Z';
for(i = ; i <= n; ++i) {
if(s[i] >= 'A' && s[i] <= 'Z') st.clear();
else {st.insert(s[i]); m = max(m, (int)st.size());}
}
printf("%d\n", m);
return ;
}
15ms
题意:有个x轴,汽车从0出发到x=a,再返回到0,一直做这样的往返运动,现在规定0->a或a->0都算一次旅行,并且一开始汽车油箱有b升油,每走一个单位要消耗一升油,现在知道x=f位置处有个加油站,每次经过可以选择加油或不加,加的话可以加满到b升,要求完成k次旅行,求最少的加油次数。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main() {
int a, b, f, k, i, j;
scanf("%d%d%d%d", &a, &b, &f, &k);
int num = , ed = b;
if(k>&&b<*f || k>&&b<*(a-f) || b<f || b<a-f) {puts("-1"); return ;}
for(i = ; i <= k; ++i) {
if(i == k && ed >= a) break;
if(i%) {
if(ed<*a-f) {num++; ed = b-(a-f);}
else ed -= a;
}
else {
if(ed<a+f) {num++; ed = b-f;}
else ed -= a;
}
}
printf("%d\n", num);
return ;
}
15ms
codeforces 864 D. Make a Permutation!【贪心】
题意:每次可以任意改变数组中的一个数,要求把数组变成1~n,求改变数的最小数量和最后的字典序最小的数组。
题解:因为要字典序最小,顺序访问没出现的数,将其与重复了的数进行判断,小的话直接替换,否则若重复的数已经被标记,则也进行替换。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 2e5+;
int n, a[N], num[N], vis[N];
int main() {
int i, j, k, cnt = , x = ;
memset(vis, , sizeof(vis));
memset(num, , sizeof(num));
scanf("%d", &n);
for(i = ; i < n; ++i) {scanf("%d", &a[i]); num[a[i]]++;}
for(i = ; i < n; ++i) {
for(; num[x]; ++x);
if(num[a[i]]> && (x < a[i] || vis[a[i]])) {
num[a[i]]--; num[a[i]=x]++; ++cnt;
}
else vis[a[i]] = ;
}
printf("%d\n", cnt);
for(i = ; i < n-; ++i) printf("%d ", a[i]);
printf("%d\n", a[n-]);
return ;
}
93ms
题意:已知第i个文件:保存所需的时间为ti,到了时间di则会毁坏,和可得的价值pi。求能保存的文件的最大价值和,以及能保存的文件的编号。
题解:给d小的赋予高优先级再对文件排序。dp[j]表示在j时间前保存的文件所能得到的最大价值和,并对选择保存的文件进行标记。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ;
const int M = ;
int n;
int dp[M], vis[N][M];
struct node {
int t, d, p, id;
bool operator < (const node&r) const{
return d < r.d;
}
}a[N];
int b[N];
int main() {
int i, j, k, t, ed = , cnt = ;
memset(dp, , sizeof(dp)); memset(vis, , sizeof(vis));
scanf("%d", &n);
for(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);
for(i = ; i <= n; ++i) {
t = a[i].t;
for(j = a[i].d-; j >= t; --j) {
if(dp[j] < dp[j-t]+a[i].p) {
dp[j] = dp[j-t] + a[i].p;
vis[i][j] = ;
}
}
}
for(i = ; i < a[n].d; ++i) if(dp[i]>dp[ed]) ed = i;
printf("%d\n", dp[ed]);
for(i = n; i >= ; --i) {
if(vis[i][ed]) {b[cnt++] = a[i].id; ed -= a[i].t;}
}
printf("%d\n", cnt);
for(i = cnt-; i > ; --i) printf("%d ", b[i]);
if(cnt) printf("%d\n", b[]);
return ;
}
15ms
Codeforces Round #436 (Div. 2)【A、B、C、D、E】的更多相关文章
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- Codeforces Round #434 (Div. 2)【A、B、C、D】
Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是 ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #435 (Div. 2)【A、B、C、D】
//在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...
- Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
- Codeforces Round #439 (Div. 2)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- Codeforces Round #430 (Div. 2) 【A、B、C、D题】
[感谢牛老板对D题的指点OTZ] codeforces 842 A. Kirill And The Game[暴力] 给定a的范围[l,r],b的范围[x,y],问是否存在a/b等于k.直接暴力判断即 ...
- Codeforces Round #676 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...
- 【做题】Codeforces Round #436 (Div. 2) F. Cities Excursions——图论+dfs
题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...
随机推荐
- 有意思的MySQL之最
写在前面 在平时工作中特别是架构设计阶段,咨询量最多的也就是MySQL之最了,在不经意间发现原来MySQL手册里面已经列举了,顺手拿来翻译下,如果有翻译错误或者不当的地方,欢迎批评指正. 最大和最小 ...
- ASP.NET MVC4 新手入门教程之三 ---3.添加视图
在这一节你要修改HelloWorldController类要使用的视图模板文件来干净封装生成 HTML 响应到客户端的过程. 您将创建一个使用Razor 视图引擎介绍 ASP.NET MVC 3 的视 ...
- javaEE Design Patter(2)详解3个设计模式
Factory (bean creating) Proxy(Agent)(Aop)书有~ Templete(springMVC Facelets)//此处及以上忽略 工厂模式(Factory) 工厂模 ...
- MySQL:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解决方法: 修改密码:alter user 'root'@'localhost' identified by '123456'; mysql> use mysql; ERROR 1820 (HY ...
- easyui前后台转义字符和普通字符的相互转换问题
昨天碰到一个问题,公司前端使用的是easyui和jquery,页面textarea编写了html代码,传入后台变成了<>类型代码,这样保存到数据库是没有问题的,但是在页面显示的时候需要显示 ...
- MVC设计模式实现权限管理登录,超详细
功能实现:在页面输入给定的用户名之一,可以显示当前用户的权限,也可以在页面更改该用户的权限,更新之后保存.像下面这样. 填写用户名提交: 显示用户AAA的权限: 修改权限(增加article3): 点 ...
- docker 数据卷挂载总结
原文
- freemarker生成word,表格分页
在做项目的过程中,使用到了freemarker生成word.又有一个需求,明细的要确定有多少页,这就用到了换页的xml标签了,找了我好久 <w:p ><w:r><w:br ...
- div的隐藏占用空间位置关系
display:none和visibility:hidden都是把网页上某个元素隐藏起来的功能,但两者有所区别,经过亲自实验,我发现使用 visibility:hidden属性会使对象不可见,但该对象 ...
- mysql 去除重复数据
1. 问题描述 有时load或者insert操作导致 表数据有重复 2. 解决方案 通过临时表.主键id.倒腾去重 示例 2.1 create table student( name varchar ...