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没有放在其他套娃里面,那么可 ...
随机推荐
- VUE温习:style层次分析
一.vue样式style层次分析 1.样式可以在main.js.模块js文件.组件style.组件script标签内,index.html文件内引入,不同位置引入的样式有什么关系. 2.总结: (1) ...
- Docker国内镜像source
现在使用docker的镜像大多基于几种基本Linux系统.虽然我不需要在容器李安装很多东西,但经常需要一些必要的工具,而基础镜像里并不包含,比如vim, ifconfig, curl等.考虑下载速度, ...
- http范围请求
基于范围请求 可以实现 断点续传和多线程分片下载 HTTP/1.1之后才支持,需要双端都支持 服务端头信息中有 Accept-Ranges:bytes 表明服务器支持范围请求 curl -I &quo ...
- 通过groovy表达式拓展oval——实现根据同一实体中的其他属性值对某个字段进行校验
在java的参数校验中,开源验证框架OVAL基本能够满足所有需求,如下面通过简单的添加注解,就可实现对参数的非空和长度校验. @NotNull(message="计息周期月数不能为空&quo ...
- 单片机成长之路(51基础篇) - 021 STC89C51系列单片机 内部EEPROM 驱动
最近又看了一下关于stc单片机的知识,感觉在使用中EEPROM是个经常用到的东西,特地学习了一下,给大家分享一下心得,如有不足,多多包涵,废话不多说,一图解千言,先上图: /*------------ ...
- 使用phpstorm进行PHP断点调试
PHP开发中都说一个会偷懒的程序员才是合格的程序员,在PHP开发中调试是必须要有的,可能要重复很多次的去调试,一次又一次,今天我们就来教教大家如何偷懒的,那么就来讲讲使用phpstorm进行偷懒吧! ...
- python--第八天总结
一.isinstance(obj, cls) 检查是否obj是否是类 cls 的对象 class Foo(object): pass obj = Foo() isinstance(obj, Foo) ...
- 判断回文字符串、回文链表、回文数(python实现)
所谓回文字符串,就是正读和反读都一样的字符串,比如"level"或者"noon"等等就是回文串.即是对称结构 判断回文字符串 方法一: def is_palin ...
- halcon 创建region的最大尺寸问题
gen_region 之类的创建region 之前需要提前设置region的最大尺寸,设置方法如下: set_system('width',2000)set_system('height',2000) ...
- rpc error: code = Internal desc = stream terminated by RST_STREAM with error code: PROTOCOL_ERROR
使用grpc-go调用grpc服务端时,出现rpc error: code = Internal desc = stream terminated by RST_STREAM with error c ...