最近不知道为啥被安利了饥荒,但是不能再玩物丧志了,不能颓了

饥荒真好玩

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的更多相关文章

  1. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual C D - Yet Another Palindrome Partitioning

    [题意]给定只含小写字母的字符串,要求分割成若干段使段内字母重组顺序后能得到回文串,求最少分割段数.n<=2*10^5 [算法]DP [题解]关键在于快速判断一个字符子串是否合法,容易发现合法仅 ...

  3. 【AtCoder】CODE FESTIVAL 2017 qual A

    A - Snuke's favorite YAKINIKU -- #include <bits/stdc++.h> #define fi first #define se second # ...

  4. 【AtCoder】CODE FESTIVAL 2017 qual C

    A - Can you get AC? No #include <bits/stdc++.h> #define fi first #define se second #define pii ...

  5. 【AtCoder】CODE FESTIVAL 2016 qual A

    CODE FESTIVAL 2016 qual A A - CODEFESTIVAL 2016 -- #include <bits/stdc++.h> #define fi first # ...

  6. 【AtCoder】CODE FESTIVAL 2016 qual B

    CODE FESTIVAL 2016 qual B A - Signboard -- #include <bits/stdc++.h> #define fi first #define s ...

  7. 【AtCoder】CODE FESTIVAL 2016 qual C

    CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...

  8. 【AtCoder】CODE FESTIVAL 2017 Final

    A - AKIBA 模拟即可 代码 #include <bits/stdc++.h> #define fi first #define se second #define pii pair ...

  9. CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】

    CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...

随机推荐

  1. u-boot移植(六)---代码修改---串口

    一.代码流程 1.1 串口代码 程序流程图如下: default_serial_console 执行的代码如下: 在JZ2440.H中有如下定义: 则执行结构体s3c24xx_serial0_devi ...

  2. PyCharm的调试

    1.设置断点 2.debug模式运行    F8      下一行代码 查看当前位置所有局部变量:print(locals()) 查看全局变量:                      print( ...

  3. mod_wsgi 的两种模式

    mod_wsgi 的两种模式 http://ssmax.net/archives/977.html http://www.cnblogs.com/yuxc/p/3555005.html mod_wsg ...

  4. js sort方法根据数组中对象的某一个属性值进行排序

    sort方法接收一个函数作为参数,这里嵌套一层函数用来接收对象属性名,其他部分代码与正常使用sort方法相同. var arr = [ {name:'zopp',age:0}, {name:'gpp' ...

  5. 2017-2018-2 20155303『网络对抗技术』Exp1:PC平台逆向破解

    2017-2018-2 『网络对抗技术』Exp1:PC平台逆向破解 --------CONTENTS-------- 1. 逆向及Bof基础实践说明 2. 直接修改程序机器指令,改变程序执行流程 3. ...

  6. Windows和Mac上NodeJS和Express的安装

    一.安装NodeJS,官网上下载,https://nodejs.org/en/ 直接下一步安装就行了. 打开命令行工具,输入 node -v 则会出现node的版本,则成功了. 下面我们介绍如何安装e ...

  7. python3数据结构与算法

    python内置的数据结构包括:列表(list).集合(set).字典(dictionary),一般情况下我们可以直接使用这些数据结构,但通常我们还需要考虑比如搜索.排序.排列以及赛选等一些常见的问题 ...

  8. Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历))

    Python3 日期时间 相关模块(time(时间) / datatime(日期时间) / calendar(日历)) 本文由 Luzhuo 编写,转发请保留该信息. 原文: http://blog. ...

  9. /etc/profile 路径出错后相关的命令失效解决方式

    关于 Linux 的配置文件 /etc/profile 路径出错后相关的命令失效解决方式(如:ls,vi不能用) 今天学习LINUX 下配置jdk 和安装tomcat 通过VI编辑/etc/profi ...

  10. Python创建、删除桌面、启动组快捷方式的例子分享

    一.Python创桌面建快捷方式的2个例子 例子一: 代码如下: import osimport pythoncomfrom win32com.shell import shell    from w ...