codeforces R 493 div2
我蓝了!蓝了!!!蒟蒻的蓝色。日常点开friend发现竟然没几个人打??然后去div1看了一下果然学长全都去打div1了呜呜呜。
看到了久违的黄大仙,以为他今晚要上grandmaster,结果打完发现他取消注册了。。。
题外话,div2半小时过完abc,d题推了一个多小时无果,div一千五百人同时在推D题,海上生明月,天涯共此时!(还好我手速快。。。)
上午考完英语三十个单选一百多个选项单词不认识。。。后天高数军理大后天大物,这几天暂时不打了。(好像也只有一场div3
A:我感觉我是瞎做的
all是整个数列的和,然后我们算前缀和sum,只要 sum!=all-sum,那么这个位置之前的都选出来就行了。注意特判个别情况
B:贪心+优先队列(或者存进数组然后排序),所有能分割的地方 都把 花费 存进来,然后前缀和<B就行。
只贴main方法,快速io太长容易引起不适,请忽略我的冒泡排序。。。
public static void main(String[] args) {
int n = nextInt();
int B = nextInt();
int ans[] = new int[n];
int index = 0;
int a[] = new int[n];
for(int i=0;i<n;i++){
a[i] = nextInt();
}
int odd = 0;
int even = 0;
for(int i=0;i<n;i++){
if (a[i]%2==0)
even++;
else
odd++;
if (even==odd){
if (i==n-1){
break;
}else {
ans[index++]=Math.abs(a[i+1]-a[i]);
odd=0;
even=0;
}
}
}
for(int i=0;i<index;i++){
for(int j=i+1;j<index;j++){
if (ans[j]<ans[i]){
int temp = ans[i];
ans[i]=ans[j];
ans[j]=temp;
}
}
}
if (index==0){
out.print(0);
out.flush();
return;
}
int sum[] = new int[index];
sum[0] = ans[0];
for(int i=1;i<index;i++){
sum[i]=sum[i-1]+ans[i];
}
for(int i=0;i<index;i++){
if (sum[i]>B){
out.print(i);
out.flush();
return;
}
}
out.print(index);
out.flush();
return;
}
C:用了十分钟过掉的,,,还是太菜了,看了好久才找到规律
很显然我们要找到 连续 0 子段 的 个数(我太菜了说不清楚),假如有n个,那么我们n次y操作一定可以,或者n-1次x操作加一次y操作。
public static void main(String[] args) {
int n = nextInt();
long x = nextLong();
long y = nextLong();
String s = next();
char ch[] = s.toCharArray();
int num = 0;
for(int i=0;i<n;){
if (ch[i]=='0'){
num++;
for(int j=i;j<n;j++){
if (ch[j]=='1'){
i=j;
break;
}
else if (j==n-1){
i=n;
break;
}
}
}else
i++;
}
if (num==0){
out.print(0);
}
else if (y<=x){
out.print(y*num);
}else {
out.print((num-1)*x+y);
}
out.flush();
}
D:毒瘤啊 刚才看了看学长的代码发现自己的思路竟然是错的,早知道半个小时过掉abc就去睡觉,也不至于今天英语考试一副要死的样子。。。
问题是我真的感觉自己要挂科了,贴一份学长的代码(大家可以努力看看。。。。。)
要是看懂了的话顺便给我讲讲,,考试周了我这种蒟蒻一般不敢打扰学长。。。
#include <iostream>
using namespace std;
typedef long long LL;
LL n; int dp[][], ans[];
void test(){
dp[][]=;
for(int i=;i<=;i++){
for(int j=;j<=;j++){
if(j>=&&dp[i-][j-]) dp[i][j]=;
if(j>=&&dp[i-][j-]) dp[i][j]=;
if(j>=&&dp[i-][j-]) dp[i][j]=;
if(j>=&&dp[i-][j-]) dp[i][j]=;
}
int cnt=;
for(int j=;j<=;j++) cnt+=dp[i][j];
ans[i]=cnt;
//printf("%d %d\n", i, cnt);
}
} int main() {
test();
cin>>n;
if(n<) printf("%d\n", ans[n]);
else printf("%lld\n", ans[]+(n-)*);
}
下面这个是黄大仙的D题,,,看了下提交记录用了不到十分钟,,不过几乎没有可读性。。。可能这就是神仙吧.jpg
#include<iostream>
#include<cstdio>
#include<bitset>
const int N=;
std::bitset<N> dp[],tmp;
int main() {
dp[][]=;
for(int i=;i<=;i++) {
tmp=dp[i-];
dp[i]|=tmp<<;
dp[i]|=tmp<<;
dp[i]|=tmp<<;
dp[i]|=tmp<<;
}
int n,ans=dp[].count();
scanf("%d",&n);
if(n<=) printf("%d\n",int(dp[n].count()));
else printf("%lld\n",1LL*(n-)*+ans);
return ;
}
codeforces R 493 div2的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- CodeForces Round 192 Div2
This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...
- codeforces 572(Div2)A、B、C、D1、D2、E
Cdoeforces 572(Div2)A.B.C.D1.D2.E 传送门:https://codeforces.com/contest/1189 A.题意: 给你一串长为n的字符串,要求你将其切割为 ...
- Codeforces Round #359 div2
Problem_A(CodeForces 686A): 题意: \[ 有n个输入, +\space d_i代表冰淇淋数目增加d_i个, -\space d_i表示某个孩纸需要d_i个, 如果你现在手里 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Codeforces Round#310 div2
C题:这题说的是套娃,如果做题的时候知道是套娃,那就好理解多了 规则1:套娃A可以放到套娃B里面,当且仅当套娃B没有放在其他套娃里面 规则2:套娃A放在套娃B里面,且套娃B没有放在其他套娃里面,那么可 ...
随机推荐
- Linux软件开发常用的软件包(持续更新中)
下面是Linux开发常用的软件包: 软件包的名称 作用描述 安装方式 build-essential sudo apt-get install build-essential policycore ...
- Unity3d XmlException: Text node cannot appear in this state的方案
这个问题是utf-8编码的问题,如果是utf-8+bom那么就会出现这种问题,如果是单纯的utf-8就没有这种问题(当然如果你把他完全变成ansi,那也行) 我在读写xml的时候遇到这个问题.查了好久 ...
- ABAP表生成Java实体Bean
项目中需要将HR模块中的表数据同步到Java系统中,向外围系统提供分发与查询服务,涉及到的表有两百多张,字段好几千上万个,如果手工一张张这些ABAP表在Java系统数据库中创建一遍的话,工作量将非常大 ...
- [开源]开放域实体抽取泛用工具 NetCore2.1
开放域实体抽取泛用工具 https://github.com/magicdict/FDDC 更新时间 2018年7月16日 By 带着兔子去旅行 开发这个工具的起源是天池大数据竞赛,FDDC2018金 ...
- 【C#】C#线程_I/O限制的异步操作
目录结构: contents structure [+] 为什么需要异步IO操作 C#的异步函数 async和await的使用 async和Task的区别 异步函数的状态机 异步函数如何转化为状态机 ...
- __NSArrayI __NSArray0 __NSSingleObjectArrayI __NSPlaceholderArray __NSArrayM
如果你的 全局 可变数组 前面 用了 copy修饰,那么 调用 arr addObjectsFromArray: 的时候 就 会崩溃,而且提示你 是 [__NSArray0 addObje ...
- shell 实例
转载自:https://github.com/liquanzhou/ops_doc 这里只作为笔记使用,不做他用 shell实例手册 0 说明{ 手册制作: 雪松 更新日期: 2018-09-1 ...
- 如何配置JVM系统属性及获取方式System.getProperty("pname")
https://www.cnblogs.com/keyi/p/7721893.html
- 【iCore4 双核心板_uC/OS-II】例程九:消息队列
一.实验说明: 前面介绍通过信息传递可以进行任务间的交流,信息也可以直接发送给一个任务,在uC/OS-II中每一个任务在它们内部都有一个消息队列,也即任务消息队列,用户可以直接给一个任务发送消息,不需 ...
- .net Core Abp See config settings - "CustomSchemaIds" for a workaround
Swagger See config settings - "CustomSchemaIds" for a workaround System.InvalidOperationE ...