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复习第一天
Day01 1.独立编写Hello World程序. public class Test{ public static void main(String[] args){ System.out.pri ...
- [javaEE] 三层架构案例-用户模块(二)
使用junit测试框架,测试查找用户和添加用户功能 com.tsh.test.xmlUserDaoTest package com.tsh.test; import org.junit.Test; i ...
- 三:Springboot整合Redis
一:springboot整合redis redis版本:3.0.0 运行环境:linux 1.安装redis 1.1安装gcc yum install gcc-c++ 1.2解压redis.3.0.0 ...
- 一:Maven知识整理
一:maven的好处 1.依赖管理:对jar包的统一管理 可以节省空间 2.项目一键构建: 编码 编译 测试(junit) 运行 打包 部署 一个 tomcat:run就能把项目运行起来 Maven能 ...
- 关于responseHeader的一些基础设置
1.关于响应头的一些基础设置 //设置相应头 response.addHeader("name","zhangsan"); response.addIntHea ...
- Java基础(四)方法和数组
一.方法 1.方法的定义 方法也叫函数,就是一个能独立完成某个功能的一段代码.方法可以看作一个整体. 语法: 修饰符 返回类型 方法名字(数据类型 变量名,数据类型 变量名,……[形式参数(0个到n个 ...
- maven(5)--依赖特性
依赖的子标签中有scope,常用值有compile.provide.test.runtime compile:编译范围有效,即编译和打包时都会将这个依赖存储 provide:编译测试有效,但是打包是将 ...
- 通过反射感知Redis类里边全部的操作方法
<?php //通过反射感知Redis类里边全部的操作方法 //根据Redis类实例化一个反射类对象 $me = new ReflectionClass('Redis'); //获得Redis类 ...
- CSS3自定义loading效果
效果: 使用CSS3完成loading的制作 css样式: <style type="text/css"> .mask { position: fixed; left: ...
- 51Nod1782 圣诞树
传送门 我居然忘写题解啦!(记忆废) 总的来说这题就是道大数据结构……看我代码长度就知道了,真的是长得要死…… …… 这题的操作都是路径修改单点查询,因此可以树上差分,问题就变成了维护子树中的所有标记 ...