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

codeforces 864 C. Bus【模拟】

题意:有个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

codeforces 864 E. Fire【DP】

题意:已知第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】的更多相关文章

  1. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  2. 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. 题解:答案就是 ...

  3. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  4. Codeforces Round #435 (Div. 2)【A、B、C、D】

    //在我对着D题发呆的时候,柴神秒掉了D题并说:这个D感觉比C题简单呀!,,我:[哭.jpg](逃 Codeforces Round #435 (Div. 2) codeforces 862 A. M ...

  5. Codeforces Round #440 (Div. 2)【A、B、C、E】

    Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...

  6. Codeforces Round #439 (Div. 2)【A、B、C、E】

    Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...

  7. 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.直接暴力判断即 ...

  8. Codeforces Round #676 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...

  9. 【做题】Codeforces Round #436 (Div. 2) F. Cities Excursions——图论+dfs

    题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...

随机推荐

  1. Java 字符串(String)格式转json格式

    json是前后端传输数据的一种文本格式,json其实就是字符串,因为前后端传输数据时,只能传输字符串,我们又想传一些对象或者列表信息,这都是很常见的应用场景. 所以,我们需要在java代码中,把jav ...

  2. 打开usb调试的方法

    方法一: settings --> about tablet --> build number(疯狂点击)  -->回退 developer options --> USB d ...

  3. JMS - ActiveMQ的简单使用

    首先需要下载ActiveMQ,下面的链接给我们列出了所有版本:http://activemq.apache.org/download-archives.html每个版本为不同的OS提供了链接: 公司电 ...

  4. sql server分页查询

    1.引言 在列表查询时由于数据量非常多,一次性查出来会非常慢,就算一次查出来了,也不能一次性显示给客户端,所以要把数据进行分批查询出来,每页显示一定量的数据,这就是数据要分页. 2.常用的数据分页方法 ...

  5. [android] 通过比对进行容器联动

    当中间容器变化之后,标题栏也要跟着变化 设计个比对依据: 抽象类BaseView中定义抽象方法,每个继承的View都必须实现,为自己的界面定义一个唯一的int常量,作为比对依据 降低容器之间的耦合度: ...

  6. request.getRequestURL()和request.getRequestURI()的区别

    request.getRequestURL() 返回全路径 request.getRequestURI() 返回除去host(域名或者ip)部分的路径 request.getContextPath() ...

  7. Filter内容

    1.利用Filter来过滤的时候大都是Http请求和Http响应,在doFilter()方法中,参数类是ServletRequest和ServletResponse  ,使用的时候一般需要强制转换为H ...

  8. mysql根据时间查询日期的优化

    例如查询昨日新注册用户,写法有如下两种: EXPLAIN select * from chess_user u where DATE_FORMAT(u.register_time,'%Y-%m-%d' ...

  9. Thrift笔记(七)--回调源码分析

    网上找了写代码,东拼西凑写了个demo.开始server用的是阻塞io,不行,换成非阻塞的io就可以.这里可能需要注意下 thrift文件 namespace java com.gxf.thrift ...

  10. Effective C++ .06 阻止编译器自动生成函数以及被他人调用

    这节讲了下如何防止对象拷贝(隐藏并不能被其他人调用) 两种方法: 1. 将拷贝构造函数声明为private 并且声明函数但不进行定义 #include <iostream> #includ ...