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的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...
随机推荐
- 冀永楠:OCR的应用锦集及背后技术
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由云加社区技术沙龙 发表于云+社区专栏 演讲嘉宾:冀永楠,现为腾讯云大数据AI产品中心高级研究员.负责了腾讯云与华星光电等多个图像AI项 ...
- k8s architecture
总体架构 对应的源码结构: https://docker-k8s-lab.readthedocs.io/en/latest/kubernetes/stepbystep.html
- 项链(burnside)
Description 有一个长度为 \(n\) 的项链,首尾相接形成环,现在你要给每一个位置一个颜色 \([1,m]\), 求所有不同的项链个数(可以通过旋转变成一样的称为相同) Solution ...
- MySql数据库与JDBC编程三
多表连接查询(两种规范 SQL92和SQL99) SQL92规范: 等值连接,非等值连接,外连接,广义笛卡儿积连接 多个表都放在from后,,连接条件放在where后,条件要求两列值相等,则为等值连接 ...
- EasyPusher推流类库的.NET调用说明
EasyPusher推流类库的.NET调用说明 以下内容基于在使用EasyPusher过程中遇到的问题,以及相应的注意事项.本文主要是基于对C++类库的二次封装(便于调试发现问题)以供C#调用以及对一 ...
- [javaEE] jsp的九大隐式对象
pageContext对象: 1.可以作为入口对象获取其他八大隐式对象的引用 1.1 getEXception获取exception隐世对象 1.2 getPage获取page对象 1.3 getRe ...
- go get 下载需要的相关工具
文档来源: https://code.google.com/p/go-wiki/wiki/GoGetTools 被墙了,所以转在这个备用. Installing Version Control Too ...
- flask之flask-sqlalchemy(一)
一 安装flask-sqlalchemy pip install flask-sqlalchemy 二 导入相关模块和对象 from flask_sqlalchemy import SQLAlchem ...
- db缓存设计
http://www.cnblogs.com/herm/archive/2012/11/11/2773887.html
- springMVC @Component-@Resource-@Repository-@Service-@Controller的区别和理解
作用: @Component------------------------泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注.(Component-------成分; 组分; 零件) @R ...