A. Left-handers, Right-handers and Ambidexters

题意

\(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可。要组成一支队伍,里面用左手的人数与用右手的人数相等,问队伍最大人数。

Code

#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long LL;
int main() {
int l,r,a;
scanf("%d%d%d", &l,&r,&a);
if (l-r>=a) printf("%d\n", r+a<<1);
else if (r-l>=a) printf("%d\n", l+a<<1);
else {
int z=l-r;
if ((z+a)&1) --a;
int y=(z+a)>>1, x=a-y;
printf("%d\n", (l+x)*2);
}
return 0;
}

B. Intercepted Message

题意

两个序列\(a,b\),总和相等,将\(a,b\)分别切成\(k\)段,对应段的子序列和相等。问最多能切成多少段。

思路

贪心

Code

#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
#define maxn 1000010
using namespace std;
int a[maxn], b[maxn];
typedef long long LL;
int main() {
int n,m;
LL s1=0, s2=0;
scanf("%d%d",&n,&m);
F(i, 0, n) scanf("%d", &a[i]);
F(i, 0, m) scanf("%d", &b[i]);
int i=0, j=0, tot=-1;
while (true) {
if (s1==s2) {
++tot;
if (i==n||j==m) break;
s1=0; s2=0;
s1 += a[i++], s2+= b[j++];
}
else if (s1<s2) s1 += a[i++];
else s2 += b[j++];
}
printf("%d\n", tot);
return 0;
}

C. Zebras

题意

一个\(01\)串,将其拆分成若干个格式为\(0101...010\)的(开头结尾均为\(0\),中间交替),每个串中的\(01\)与原序列中的先后顺序相同。要求给出方案。

思路

两个\(set\)分别记录\(0\)的位置和\(1\)的位置,配合\(lower\_bound\)使用。

结束条件:

  1. \(0\)的\(set\)为空
  2. \(1\)的\(set\)为空
  3. \(1\)的\(set\)与前一次不发生变化

Code

#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
#define maxn 400010
using namespace std;
char s[maxn];
set<int> st[2];
vector<int> v[maxn];
typedef long long LL;
int main() {
scanf("%s", s);
int len = strlen(s);
F(i, 0, len) {
if (s[i]=='0') st[0].insert(i);
else st[1].insert(i);
}
int cnt=-1;
int count=0, temp=-1;
while (true) {
if (st[1].size()==temp || !st[0].size() || !st[1].size()) {
if (st[1].size()) puts("-1");
else {
printf("%d\n", cnt+1+st[0].size());
F2(i, 0, cnt) {
printf("%d ", v[i].size());
for (auto x : v[i]) printf("%d ", x+1); puts("");
}
for (auto x : st[0]) printf("%d %d\n", 1, x+1);
}
break;
}
temp = st[1].size();
int cur=0, x=-1;
++cnt;
while (true) {
auto it = st[cur].lower_bound(x);
if (it == st[cur].end()) {
if (cur==0) {
st[1].insert(x);
v[cnt].pop_back();
}
break;
}
else {
v[cnt].push_back(*it);
x = *it;
st[cur].erase(it);
cur = !cur;
}
}
}
return 0;
}

D. A Leapfrog in the Array

题意

思路

找呀找呀找规律。

元素\(x\)跳\(k\)次的步长分别为\((2(n-x)+1)*(1,2,4,8,...\),

所以跳\(k\)次后的位置为\(2x-1-(2(n-x)+1)(2^{k+1}-1)=(2x-1-2n)*2^{k+1}+2n\),

所以\(P_{k+1}=(2x-1-2n)*2^{k+2}+2n\),

所以\(P_{k}=P_{k+1}/2+n\)

于是可以从当前位置一路往后推,推到下标为奇数为止。

Code

#include <bits/stdc++.h>
#define F(i, a, b) for (int i = (a); i < (b); ++i)
#define F2(i, a, b) for (int i = (a); i <= (b); ++i)
#define dF(i, a, b) for (int i = (a); i > (b); --i)
#define dF2(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
typedef long long LL;
LL n; int q;
LL calc(LL x) {
if (x&1) return (x+1)>>1;
return calc(n+(x>>1));
}
int main() {
scanf("%I64d%d", &n,&q);
while (q--) {
LL x, ans;
scanf("%I64d", &x);
printf("%I64d\n", calc(x));
}
return 0;
}

E. Data Center Maintenance

具体见 http://www.cnblogs.com/kkkkahlua/p/8541916.html

反思

开学打了两场均一塌糊涂。

挺多原因吧,包括各种外界环境以及干扰啥的,心态也浮躁,也可能是这几天睡得都比较晚,归根到底还是菜。

就今天这场而言,

\(A,B\)写得都很慢,

\(C\)题一开始因为输出格式错误在\(pretest\ 1\)都挂了好几次,后来\(T\)了一次,然后想到用\(set\)还挺高兴的,结果不明原因的一直\(RE\),本地一直跑也跑不出问题,就只能放弃了。

比赛结束麻烦同学跑才发现st[cur].erase(it); x = *it; // 别人家的IDE

我也是很强了,\(erase\)完还去取它的值。

\(C\)题没辙了就去看\(D\)题,还挺快就找到了初步的规律,也就是找到了\(P_k\),然而没有化简,于是就愣没看出来能怎么用。明明是这么棒的递推啊。

心浮气躁。可以的。

暂时的状态看起来不太能打了...。

等稍微进入正轨吧。学习上要忙的事情也是很多啊。

有闲情的话可以打打virtual,然后等天时地利人和。

再菜也还是要努力地活下去呢。

晚安晚安。

Codeforces Round #469 Div. 2 A B C D E的更多相关文章

  1. Codeforces Round #469 (Div. 2)

    Codeforces Round #469 (Div. 2) 难得的下午场,又掉分了.... Problem A: 怎么暴力怎么写. #include<bits/stdc++.h> #de ...

  2. Codeforces Round #469 (Div. 1) 949C C. Data Center Maintenance (Div. 2 950E)

    题 OvO http://codeforces.com/contest/949/problem/C codeforces 949C 950E 解 建图,记原图为 G1,缩点,记缩完点后的新图为G2 缩 ...

  3. Codeforces Round #469 (Div. 2)C. Zebras(思维+模拟)

    C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standa ...

  4. Codeforces Round #469 (Div. 2) F. Curfew

    贪心 题目大意,有2个宿管分别从1和n开始检查房间,记录人数不为n的房间个数,然后锁住房间. 没有被锁的房间中的学生可以选择藏在床底,留在原地,或者转移(最远转移d个房间)   然后抄了网上大神的代码 ...

  5. Codeforces Round #469 (Div. 2) E. Data Center Maintenance

    tarjan 题意: 有n个数据维护中心,每个在h小时中需要1个小时维护,有m个雇主,他们的中心分别为c1,c2,要求这两个数据中心不能同时维护. 现在要挑出一个数据中心的子集,把他们的维护时间都推后 ...

  6. Codeforces Round #469 Div. 2题解

    A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...

  7. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. ABP官方文档

    https://aspnetboilerplate.com/Pages/Documents/Introduction

  2. 《python核心编程第二版》第5章习题

    5-1 整形 讲讲 Python 普通整型和长整型的区别 答:普通整型 32位,长整数类型能表达的 数值仅仅与你的机器支持的(虚拟)内存大小有关 5-2 运算符(a) 写一个函数,计算并返回两个数的乘 ...

  3. 解决灰色shader与mask冲突的方案

    Shader "Custom/Opaque" { Properties { [PerRendererData] _MainTex ("Sprite Texture&quo ...

  4. 问题 A: Least Common Multiple

    题目描述 The least common multiple (LCM) of a set of positive integers is the smallest positive integer ...

  5. jira+mysql+破解+中文+compose

    1.制作docker-compose.yml 2.安装 $ docker stack deploy -c docker-compose.yml mshk_jira

  6. 树莓派搭建 Hexo 博客(一)

    Hexo 一个开源的博客框架,本文记录了一下在树莓派上搭建 Hexo 博客的过程. 什么是 Hexo? Hexo 是一个快速.简洁且高效的博客框架.Hexo 使用 Markdown(或其他渲染引擎)解 ...

  7. Alpha阶段展示

    程序员杀产品经理祭天(SacrificePM)团队 1.团队成员简介和个人博客地址 故事 我们队伍的建立过程稍具戏剧性,大家看我们也颇为奇怪,这么一支8人队伍是怎么诞生的呢?其实我们原本分属三组,而第 ...

  8. php实现base64图片上传方式实例代码

    <?php /** * base64图片上传 * @param $base64_img * @return array */ header("content-type:text/htm ...

  9. 微服务日志监控与查询logstash + kafka + elasticsearch

    使用 logstash + kafka + elasticsearch 实现日志监控 https://blog.csdn.net/github_39939645/article/details/788 ...

  10. SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase

    sqlserver 插入数据的时候 插入失败,报错内容为 “SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, ...