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没有放在其他套娃里面,那么可 ...
随机推荐
- Android Studio提示 Connection reset
解决步骤: 1:Android studio开发工具:File -> Invalidate caches / Restart:选择Invalidate and Restart关闭 Android ...
- nginx -- 单独访问某个页面404
- 面向对象编程技术的总结和理解(c++)
目录树 1.继承 1.1 基类成员在派生类中的访问属性 1.2继承时导致的二义性 1.3 多基继承 2.虚函数的多态 2.1虚函数的定义 2.2派生类中可以根据需要对虚函数进行重定义 2.3 虚函数的 ...
- iterm快捷键设置
如图所示,选择相应的动作和快捷键组合
- FakeUserAgentError('Maximum amount of retries reached') 彻底解决办法
报错: FakeUserAgentError('Maximum amount of retries reached') 禁用服务器缓存: ua = UserAgent(use_cache_server ...
- android:Android中用文件初始化sqlite数据库(zz)
很多时候在应用安装初始化时,需要创建本地数据库,同时为数据库添加数据,之后再从数据库中读取数据. 这里有2个思路 1.先在本地创建一个能支持android使用的sqlite数据库文件,启动时, ...
- grid - 通过网格区域命名和定位网格项目
1.像网格线名称一样,网格区域的名称也可以使用grid-template-areas属性来命名.引用网格区域名称也可以设置网格项目位置. 设置网格区域的名称应该放置在单引号或双引号内,每个名称由一个空 ...
- 每天一个linux命令(5):rmdir
1.命令简介 rmdir (Remove Directory删除目录): 用来删除空目录,删除某目录时也必须具有对父目录的写权限. 2.用法 用法:rmdir [选项]... 目录... 3.选项 - ...
- BitBlt 函数 详解, StretchBlt、SetStretchBltMode、SetBrushOrgEx 按句柄截图、直接截取缩略图
BitBlt 该函数对指定的源设备环境区域中的像素进行位块(bit_block)转换,以传送到目标设备环境. 函数原型 [DllImport("gdi32.dll")] publi ...
- 自建证书配置HTTPS服务器
1.写这篇博客的初衷是因为最近iOS9出来了,苹果官方默认要求使用HTTPS,所以自己想整一个HTTPS服务器,也想好好了解一下HTTPS通信,也知道了HTTPS其实就是在HTTP的基础上加上了SSL ...