【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: ...
随机推荐
- Nginx管理脚本
#!/bin/bash # chkconfig: # description: Start/Stop Nginx server path=/application/nginx/sbin pid=/ap ...
- 二、Internet地址结构
IP路由器实现的转发程序使用IP地址来识别流量去向.IP地址也表示流量来源. 2.1 IP地址的表示 IPV4地址通常采用点分四组或点分十进制表示法,如192.168.1.1. 点分四组表示法由四个用 ...
- JavaScript之小工具之日志log()[兼容]
function log(){ try{ console.log.apply(console,arguments); }catch(e){ try{ opera.postError.apply(ope ...
- SpringBoot使用其他的Servlet容器
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- VxWorks软件开发项目实例完全解析1-VxWorks简介
1.前言 VxWorks是专门为实时嵌入式系统设计开发的32位操作系统.主要有如下特点: 实时性强 支持多任务 体积小可裁剪 支持多种CPU 支持网络通信串口通信 汇编+标准C的编程模式.支持C++ ...
- 利用capability特征加强Linux系统安全【转】
转自:https://blog.csdn.net/fivedragon/article/details/676849 1.简介 UNIX是一种安全操作系统,它给普通用户尽可能低的权限,而把全部的系统权 ...
- malloc 函数详解【转】
转自:https://www.cnblogs.com/Commence/p/5785912.html 很多学过C的人对malloc都不是很了解,知道使用malloc要加头文件,知道malloc是分配一 ...
- sqlserver 日志传送
可以使用日志传送将事务日志不间断地从一个数据库(主数据库)发送到另一个数据库(辅助数据库).不间断地备份主数据库中的事务日志,然后将它们复制并还原到辅助数据库,这将使辅助数据库与主数据库基本保持同步. ...
- 单个 LINQ to Entities 查询中的两个结构上不兼容的初始化过程中出现类型“XXXX”
最近在做一个报表的时候,用EF使用了Contact方法,但是程式运行一直出错.最近终于找到原因了,写下来提醒下自己.好了,进入正题: 现在我举个栗子,目前数据库中有ParentStudent表和Sub ...
- Cookie/Session机制详解(转载)
原文链接:http://blog.csdn.net/fangaoxin/article/details/6952954 会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用 ...