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

饥荒真好玩

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. 收集服务器网卡和IP信息

    收集服务器网卡和IP信息 Python2环境 #!/usr/bin/python2 # -*- coding:utf-8 -*- import os,sys import socket, fcntl, ...

  2. 在安卓上用Termux安装sqlmap

    1.打开Termux执行以下命令 apt update apt install git apt install python2 // 安装sqlmap运行环境 2.从github上下载sqlmap , ...

  3. 20155306 2016-2017-2 《Java程序设计》第九周学习总结

    20155306 2016-2017-2 <Java程序设计>第九周学习总结 教材学习内容总结 第十六章 整合数据库 16.1 JDBC入门 Java语言访问数据库的一种规范,是一套API ...

  4. asp.net mvc4 在EF新增的时候报对一个实体或多个实体验证失败

    //entity为空 是数据库上下文会验证实体验证 var entity = db.UserInfo.Where(u => u.Mobile == mobile).FirstOrDefault( ...

  5. 字体选择框QFontComboBox

    self.combobox_2 = QFontComboBox(self)  # 实例化字体列表框 combobox.currentFont()  返回字体选择框中当前的字体 self.combobo ...

  6. [JLOI2015]装备购买 (高斯消元)

    [JLOI2015]装备购买 \(solution:\) 首先这道题的题面已经非常清晰的告诉我们这就是线性空间高斯消元的一道题(可以用某些装备来表示另一件装备,这已经不能再明显了),只是这道题要求我们 ...

  7. 参数在一个线程中各个函数之间互相传递的问题(ThreadLocal)

    ThreadLocal最常用的地方就是为每个线程绑定一个数据库连接,HTTP请求,用户身份信息等,这样一个线程的所有调用到的处理函数都可以非常方便地访问这些资源. 一个ThreadLocal变量虽然是 ...

  8. SpringBoot注解把配置文件自动映射到属性和实体类实战

    SpringBoot注解把配置文件自动映射到属性和实体类实战 简介:讲解使用@value注解配置文件自动映射到属性和实体类 1.配置文件加载 方式一 1.Controller上面配置 @Propert ...

  9. 2018-2019-2 网络对抗技术 20165227 Exp5 MSF基础应用

    2018-2019-2 网络对抗技术 20165227 Exp5 MSF基础应用 Exploit选取 主动攻击:ms17_010_eternalblue(成功) 浏览器攻击: ms10_042_hel ...

  10. DFP算法(转载)

    转载链接:http://blog.csdn.net/itplus/article/details/21896981 注意:式(2.25)中,蓝色变量之所以是实数可以根据它们的矩阵系数相乘为1*1得到.