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的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...
随机推荐
- java文件在没有安装jdk的windows下运行。
1.首先该工程最好是gui的,使用swing或者awt的都行. 2.使用eclipse打包jar文件. 项目名字上面点右键,选择Export,在选择java\JAR file. 选择src文件夹 ...
- Magento 2开发教程 - 如何添加新产品属性
添加产品属性是一种在Magento 1 和 Magento 2最受欢迎的业务. 属性是解决许多与产品相关的实际任务的有力方法. 这是一个相当广泛的话题,但在这个视频中,我们将讨论添加一个下拉类型属性到 ...
- vue 使用Slot 分发内容 学习总结。
https://cn.vuejs.org/v2/guide/components.html#使用-Slot-分发内容 官方API地址 我对solt的理解是当组件中某一项需要单独定义,那么就应该使 ...
- [转]what’s the difference between @Component ,@Repository & @Service annotations in Spring
原文地址:https://www.cnblogs.com/softidea/p/6070314.html @Component is equivalent to <bean> @Servi ...
- 二:SpringMVC知识整理
springmvc复习: 1.SpringMVC介绍 2.SpringMVC入门程序 1)创建web工程 2)导入jar包 3)在web.xml中配置前端控制器(指定上下文件的路径 classpath ...
- 二:SpringAOP
一:AOP 面向切面编程思想 横向重复,纵向抽取 |- filter中 |- 动态代理 |- interceptor中 二:动态代理 1.通过动态代理可以体现aop思想 2.对目标对象中的方法进行增强 ...
- golang 应用的部署相关技术
nohup命令 在 linux 下面部署,我们可以利用 nohup 命令,把应用部署在后端,如下所示: nohup ./yourapp & 这样你的应用就跑在了 Linux 系统的守护进程 n ...
- SZU2
CF:Problem 425A 区间暴力,枚举区间.交换选定区间最小值和剩余区间最大值k次. 其实等同于将剩余区间最大k个加到选定区间里,然后排序 #include <iostream> ...
- struts2 执行流程及工作原理
在Struts2框架中的处理大概分为以下的步骤 1 用户发送请求: 2 这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做ActionContextCleanUp的可选过滤器,这个过 ...
- PHP三维优先级运算
昨天去某大型公司面试,做了一套面试题,整套面试题的基础要求比较高,对于js的使用有一定的要求.在本次面试中碰到PHP三维运算优先级的问题,先看题: <?php $b=20; $c=40; $a= ...