【AtCoder】CODE FESTIVAL 2017 qual B
最近不知道为啥被安利了饥荒,但是不能再玩物丧志了,不能颓了
饥荒真好玩
A - XXFESTIVAL
CCFESTIVAL
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
char s[55];
int L;
void Solve() {
scanf("%s",s + 1);
L = strlen(s + 1);
for(int i = 1 ; i <= L - 8 ; ++i) {
putchar(s[i]);
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
B - Problem Set
当然是选择出毒瘤题了
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,M;
map<int,int> zz;
void Solve() {
read(N);int a;
for(int i = 1 ; i <= N ; ++i) {
read(a);zz[a]++;
}
read(M);
for(int i = 1 ; i <= M ; ++i) {
read(a);
if(zz[a]) {
zz[a]--;
}
else {puts("NO");return;}
}
puts("YES");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
C - 3 Steps
如果图是二分图,那么可以补的边是把点黑白染色后,所有黑点都可以跟白点连边
如果不是二分图,因为一个奇环,那么任意两点之间都可以连边,用最后图的边数减去原来的边数即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct node {
int to,next;
}E[MAXN];
int deg[MAXN],head[MAXN],sumE,N,M;
int cnt[2],col[MAXN];
void add(int u,int v) {
E[++sumE].to = v;
E[sumE].next = head[u];
head[u] = sumE;
}
bool dfs(int u) {
if(col[u] == -1) col[u] = 0;
++cnt[col[u]];
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(col[v] == -1) {
col[v] = col[u] ^ 1;
if(!dfs(v)) return false;
}
else if(col[v] == col[u]) return false;
}
return true;
}
void Solve() {
read(N);read(M);
int a,b;
for(int i = 1 ; i <= M ; ++i) {
read(a);read(b);
deg[a]++;deg[b]++;
add(a,b);add(b,a);
}
memset(col,-1,sizeof(col));
if(!dfs(1)) {
out(1LL * N * (N - 1) / 2 - M);enter;
}
else {
int64 ans = 0;
for(int i = 1 ; i <= N ; ++i) {
if(col[i]) ans += cnt[col[i] ^ 1] - deg[i];
}
out(ans);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
D - 101 to 010
可以用一个dp实现
划分1011111111(k个1)或11111111101(k个1),价值都是k - 1
如果这个位置连着的连续的1超过1个,最多就一种划分
如果这个位置连着的一个1,那么可以更新01的0前面一段的1
每个位置最多换两次,复杂度\(O(N)\)
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 500005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,dp[MAXN],pre[MAXN];
char s[MAXN];
void Solve() {
read(N);
scanf("%s",s + 1);
for(int i = 1 ; i <= N ; ++i) {
if(s[i] == '0') pre[i] = i;
else pre[i] = pre[i - 1];
}
for(int i = 1 ; i <= N ; ++i) {
dp[i] = dp[i - 1];
if(s[i] == '1') {
if(pre[i] == 0) continue;
int a = pre[i],b = pre[a - 1];
if(b == a - 1) continue;
dp[i] = max(dp[a - 2] + i - a,dp[i]);
if(i - a == 1) {
for(int j = b ; j <= a - 2 ; ++j) {
dp[i] = max(dp[j] + a - j - 1,dp[i]);
}
}
}
}
out(dp[N]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
E - Popping Balls
一道有趣的计数题
就是还是改成二维平面上的点\((A,B)\)求走到\((0,0)\)的路径
相当于从\((t - 1,0)\)画一条弧度为\(\frac{3\pi}{4}\)的线和一条垂直于x轴的直线
这两条直线上方的部分可以往下走
\((s - 1,0)\)同理
然后就相当于,枚举一个t,从起点走到边界时第一步是向下(因为如果进入了区域内还左走可以把这个区域往左平移,能走到的地方更多
然后在斜的边界上找一个点,枚举一个点\(p,q\)然后往左走走到s的边界同理,方案数是一个组合数的前缀和
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 4005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int MOD = 1000000007;
int A,B;
int C[MAXN][MAXN],sum[MAXN][MAXN],s[MAXN][MAXN];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
void Solve() {
read(A);read(B);
C[0][0] = 1;
sum[0][0] = 1;
for(int i = 1 ; i <= A + B ; ++i) {
C[i][0] = 1;
sum[i][0] = 1;
for(int j = 1 ; j <= i ; ++j) {
C[i][j] = inc(C[i - 1][j],C[i - 1][j - 1]);
sum[i][j] = inc(C[i][j],sum[i][j - 1]);
}
}
for(int j = 0 ; j <= B ; ++j) {
s[j][0] = 1;
for(int i = 1 ; i <= A + B ; ++i) {
s[j][i] = inc(s[j][i - 1],sum[j][min(i,j)]);
}
}
int ans = 0;
for(int t = A; t >= 0 ; --t) {
for(int i = 0 ; i <= t ; ++i) {
int w = C[B - 1][i];
if(!i) update(ans,w);
else {
update(ans,mul(w,s[i - 1][t - i]));
}
}
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
F - Largest Smallest Cyclic Shift
每次找最小的字符和最大的字符组合成一个新的字符串,把这个字符串当成一个新字符插入集合中
直到只剩一种字符
就是每次最小的字符串一定是循环串的开头,然后从后往前把这个字符串加上一个当前最大的字符串,最大的字符串就越靠前
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 4005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct node {
string s;int num;
friend bool operator < (const node &a,const node &b) {
return a.s < b.s;
}
};
set<node> S;
int x,y,z;
void Solve() {
read(x);read(y);read(z);
if(x) S.insert((node){"a",x});
if(y) S.insert((node){"b",y});
if(z) S.insert((node){"c",z});
while(1) {
if(S.size() == 1) {
node p = *S.begin();
for(int i = 1 ; i <= p.num ; ++i) {
cout << p.s;
}
enter;
break;
}
node s0 = *S.begin(),t0 = *(--S.end());
S.erase(S.begin());S.erase(--S.end());
int k = min(s0.num,t0.num);
S.insert((node){s0.s + t0.s,k});
if(s0.num > k) S.insert((node){s0.s,s0.num - k});
if(t0.num > k) S.insert((node){t0.s,t0.num - k});
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
【AtCoder】CODE FESTIVAL 2017 qual B的更多相关文章
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【Atcoder】CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning
[题意]给定只含小写字母的字符串,要求分割成若干段使段内字母重组顺序后能得到回文串,求最少分割段数.n<=2*10^5 [算法]DP [题解]关键在于快速判断一个字符子串是否合法,容易发现合法仅 ...
- 【AtCoder】CODE FESTIVAL 2017 qual A
A - Snuke's favorite YAKINIKU -- #include <bits/stdc++.h> #define fi first #define se second # ...
- 【AtCoder】CODE FESTIVAL 2017 qual C
A - Can you get AC? No #include <bits/stdc++.h> #define fi first #define se second #define pii ...
- 【AtCoder】CODE FESTIVAL 2016 qual A
CODE FESTIVAL 2016 qual A A - CODEFESTIVAL 2016 -- #include <bits/stdc++.h> #define fi first # ...
- 【AtCoder】CODE FESTIVAL 2016 qual B
CODE FESTIVAL 2016 qual B A - Signboard -- #include <bits/stdc++.h> #define fi first #define s ...
- 【AtCoder】CODE FESTIVAL 2016 qual C
CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...
- 【AtCoder】CODE FESTIVAL 2017 Final
A - AKIBA 模拟即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair ...
- CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】
CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...
随机推荐
- postgresql 随机函数
随机函数 --function to get random number============================================================= -- ...
- python番外篇--sql注入
一.sql注入概念介绍 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将(恶意的)S ...
- 序列化时提示There was an error reflecting type 'System.Collections.Generic.List`1
序列化xml文件到List中,非win10下出现了这个错误,但是在win10下正常.经过仔细的研究,发现是序列化工具类不能使用Static.去掉Static即可.
- Elastic Job入门(3) - 集成Springboot
引入pom文件 <dependency> <groupId>com.dangdang</groupId> <artifactId>elastic-job ...
- Linux监控工具Spotlight on Unix
1.介绍 Spotlight on Unix是一款Linux系统运行状况的监控工具,可以安装在Windows下,监控Linux服务器的运行状况. 监控项目包括:CPU.内存.交换空间.虚拟内存等的使用 ...
- $PollardRho$ 算法及其优化详解
\(PollardRho\) 算法总结: Pollard Rho是一个非常玄学的算法,用于在\(O(n^{1/4})\)的期望时间复杂度内计算合数n的某个非平凡因子(除了1和它本身以外能整除它的数). ...
- 【centos】 error: command 'gcc' failed with exit status 1
原文连接http://blog.csdn.net/fenglifeng1987/article/details/38057193 用安装Python模块出现error: command 'gcc' f ...
- 【黑客免杀攻防】读书笔记6 - PE文件知识在免杀中的应用
0x1 PE文件与免杀思路 基于PE文件结构知识的免杀技术主要用于对抗启发式扫描. 通过修改PE文件中的一些关键点来达到欺骗反病毒软件的目的. 修改区段名 1.1 移动PE文件头位置免杀 工具:PeC ...
- 【Shell】带颜色输出(白底x色)
echo -e "\033[31mHello World.\033[0m" 红色31m 绿色32m 黄色33m 蓝色34m 黑色30m 白色37m 紫色35m 深绿色36m
- .net active up mail 邮件发送
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...