Codeforces Round #517 (Div. 2)
A
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for(int a = b; a <= c;++ a)
#define per(a,b,c) for(int a = b; a >= c; -- a)
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c >'9'){ if(c == '-') f = -1; c = gc; }
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-'); x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0') ;
}
int main() {
int n = read(),m =read(),k = read();
int xu=1,xd=n,yu=1,yd=m,ans=0;
while(k --) {
if(xu>xd || yu > yd) break;
ans += 2 * (xd - xu + 1) + 2 * (yd - yu + 1) - 4;
xd -=2 , xu += 2, yd -= 2, yu += 2;
}
print(ans);
return 0;
}
B
枚举尾项往前推
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for(int a = b; a <= c;++ a)
#define per(a,b,c) for(int a = b; a >= c; -- a)
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c >'9'){ if(c == '-') f = -1; c = gc; }
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-'); x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0') ;
}
int n,k;
const int maxn = 100007;
int a[maxn][2],b[maxn][2],ans[maxn][2];
bool Check() {
for(int i = n - 1;i;-- i)
for(int j = 0;j < 2;++ j) {
if(a[i][j] && b[i][j]) {
if(!ans[i + 1][j]) return false;
ans[i][j] = 1;
}
else if(!a[i][j] && !b[i][j]) {
if(ans[i + 1][j]) return false ;
ans[i][j] = 0;
}
else if(!a[i][j] && b[i][j]) return false;
else if(a[i][j] && !b[i][j]) {
if(ans[i + 1][j]) ans[i][j] = 0;
else ans[i][j] = 1;
}
}
for(int i = 1;i < n;++ i)
for(int j = 0;j < 2;++ j)
if((a[i][j] != (ans[i][j] | ans[i + 1][j])) || (b[i][j] != (ans[i][j] & ans[i + 1][j])))
return false;
puts("YES");
for(int i = 1;i <= n;++ i) print(ans[i][1] * 2 + ans[i][0]),pc(' ');
return true;
}
int main() {
n=read();
for(int i =1,ai;i < n;++ i) {
ai = read();
a[i][0] = ai & 1;
a[i][1] = ai >> 1 & 1;
}
for(int i=1,bi;i < n;++ i) {
bi = read();
b[i][0]=bi&1;
b[i][1] = bi >> 1 & 1;
}
ans[n][0] = 0, ans[n][1] = 0;
if(Check())return 0;
ans[n][0] = 0, ans[n][1] = 1;
if(Check())return 0;
ans[n][0] = 1, ans[n][1] = 0;
if(Check())return 0;
ans[n][0] = 1, ans[n][1] = 1;
if(Check())return 0;
puts("NO");
return 0;
}
C
二分最大能构成的1-n
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for(int a = b; a <= c;++ a)
#define per(a,b,c) for(int a = b; a >= c; -- a)
#define gc getchar()
#define pc putchar
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c >'9'){ if(c == '-') f = -1; c = gc; }
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-'); x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0') ;
}
int tot = 0;
const int maxn = 10000007;
int ans1[maxn],a1,ans2[maxn],a2,vis[maxn];
int A,B,n,m;
bool judge(int x) {
int a = A,b = B;
while(x) {
if(a < b) std::swap(a,b);
if(a < x) return false;
a -= x, -- x;
}
return true;
}
int main() {
A = read(),B = read(),n = 0,m = 0;
int l=0,r=1e6,mid,ans=0;
while(l <= r) {
if(judge(mid = l + r >> 1)) l = mid + 1,ans = mid;
else r = mid - 1;
}
for(int i = ans;i; -- i)
if(A < B) B -= i, ans2[++ m] = i;
else A -= i, ans1[++ n] = i;
print(n);
pc('\n');
for(int i = n;i;-- i) print(ans1[i]),pc(' '); pc('\n');
print(m);
pc('\n');
for(int i=m; i; --i) print(ans2[i]),pc(' '); pc('\n');
return 0;
}
D
找到最远的能使得前缀为a的点,bfs求字典序最小路径
#include<vector>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define rep(a,b,c) for(int a = b; a <= c;++ a)
#define per(a,b,c) for(int a = b; a >= c; -- a)
#define gc getchar()
#define pc putchar
#define pr pair<int,int>
inline int read() {
int x = 0,f = 1;
char c = gc;
while(c < '0' || c >'9'){ if(c == '-') f = -1; c = gc; }
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc;
return x * f;
}
void print(int x) {
if(x < 0) {
pc('-'); x = -x;
}
if(x >= 10) print(x / 10);
pc(x % 10 + '0') ;
}
const int maxn = 4007;
#define mp make_pair
#define fi first
#define se second
int n,k,f[maxn][maxn],mx;
char s[maxn][maxn];
vector<pr> v;
#define INF 0x3f3f3f3f;
bool vis[maxn][maxn];
void bfs() {
vector<int> path;
memset(vis,0,sizeof(vis));
vector<pr> nxt;
int xxx = v[1].fi,yyy = v[1].se;
for(int i = 0;i < v.size();++ i) {
int X = v[i].fi,Y = v[i].se;
vis[X][Y] = 1;
nxt.push_back(v[i]);
}
for(int i = 0; i < n * 2 - (xxx + yyy); i++) {
int min_col = INF;
for(int j = 0;j < nxt.size(); j++){
int xx = nxt[j].fi,yy = nxt[j].se;
for(int k = 0;k <= 1;++ k) {
int tx = (k & 1) ? xx + 1 : xx;
int ty = !(k & 1) ? yy + 1 : yy;
if(tx > n || ty > n) continue;
min_col = min(min_col,s[tx][ty] - 'a');
}
}
path.push_back(min_col);
vector<pr> nxt2;
for(int j = 0; j < nxt.size(); j++) {
int xx = nxt[j].fi,yy = nxt[j].se;
for(int k = 0;k <= 1;++ k) {
int tx = (k & 1) ? xx + 1 : xx;
int ty = !(k & 1) ? yy + 1 : yy;
if(tx > n || ty > n) continue;
if(!vis[tx][ty] && s[tx][ty] - 'a' == min_col) {
vis[tx][ty] = 1;
nxt2.push_back(mp(tx,ty));
}
}
}
nxt = nxt2;
}
for(int i = 1; i <= mx; i++) pc('a');
for(int i = 0; i < path.size(); i ++) {
pc(path[i] + 'a');
}
}
int GG,id[maxn][maxn];
int main() {
n = read(); k = read();
for(int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
for(int i = 1; i <= n; i++) s[i][0] = 'z' + 1;
for(int i = 1; i <= n; i++) s[0][i] = s[n + 1][i] = 'z' + 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
id[i][j] = ++GG;
f[i][j] = max(f[i - 1][j], f[i][j - 1]);
if(s[i][j] == 'a') f[i][j]++;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
int ned = i + j - f[i][j] - 1;
if(ned <= k) {
if(i + j > mx) v.clear(), v.push_back(mp(i, j)), mx = i + j;
else if(i + j == mx) v.push_back(mp(i, j));
}
}
}
mx --;
//print(mx);
bfs();
return 0;
}
Codeforces Round #517 (Div. 2)的更多相关文章
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)
Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path
http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)
https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...
- Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)
https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...
- Codeforces Round #517 (Div. 2)(1~n的分配)
题:https://codeforces.com/contest/1072/problem/C 思路:首先找到最大的x,使得x*(x+1)/2 <= a+b 那么一定存在一种分割使得 a1 &l ...
- Codeforces Round #517 Div. 2/Div. 1
\(n\)天没更博了,因为被膜你赛的毒瘤题虐哭了... 既然打了这次CF还是纪念一下. 看看NOIP之前,接下来几场的时间都不好.这应该是最后一场CF了,差\(4\)分上紫也是一个遗憾吧. A 给一个 ...
- Codeforces Round #517 Div. 1翻车记
A:真的懵逼了.冷静了半天之后决定二分一下答案,然后先a安排上尽量小的再贪心地一个个扩大.40min才过.这个做法非常怂的以代码复杂度和时间复杂度为代价换取了比较稳的正确性,事实上由于1~n可以组合出 ...
- Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)D(思维,DP,字符串)
#include<bits/stdc++.h>using namespace std;char c[2007][2007];char ans[4007];int s[2007][2007] ...
- 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 ...
随机推荐
- C#概念总结(五)
1.C#特性 (Attribute) 特性适用于在运行时传递程序中的各中元素(比如 类.方法.结构.枚举.组件)的行为信息额声明性标签,可以通过使用特性向程序添加声明性信息,一个声明标签是通过放置在他 ...
- mysql 5.7 ERROR 1820 (HY000):
在首次登录Mysql 5.7 后,mysql数据库做出了很多的调整.执行大部分操作会提示这个错误 : ERROR 1820 (HY000): You must reset your password ...
- linux基础练习题(2)
Linux命令作业(关卡二) 练习题1 理解操作系统的作用,以及各种操作系统的不同 要求: 为什么要有OS?没有OS能行吗?原因是什么? Linux内核指的是什么? Linux主要应用在哪些地方? 使 ...
- 基本 TCP 的回射服务器
实验一 代码:链接[01项目] 1. 先启动服务器,如图: 2. 然后启动客户端,如图: 3. 输出结果: [注意]:在服务器终止时,给父进程发送了一个SIGCHILD信号,这一点本例发生了,但是我们 ...
- CSS预处理器—Sass、LESS和Stylus
http://www.w3cplus.com/css/css-preprocessor-sass-vs-less-stylus-2.html 一.什么是CSS预处器 CSS预处理器定义了一种新的语言, ...
- ExceptionLess的webAPI调用
引用 <package id="bootstrap" version="3.0.0" targetFramework="net461" ...
- 上传文件---未能找到路径“D:\MyProject\Files\”的一部分
C# 使用控件FileUpload 上传文件,简单实例: protected void btnUpload_Click(object sender, EventArgs e) { string pat ...
- 【BZOJ3379】[Usaco2004 Open]Turning in Homework 交作业
题解: 比较容易想到二分答案+时间逆流 这样就变成了经典的路灯问题 f[a][b][0/1] 其实可以不用二分答案 根据倒着考虑我们会发现一定是先走旁边的再走中间的 计算到当前点+下课时间所需的最小时 ...
- alpha冲刺4/10
目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客:hjj 作业博客:冲刺4 团队部分 后敬甲 过去两天完成了哪些任务 文字描述 主页部分图标的替换 -拍照按钮的设计和测试 GitHub代码 ...
- 基于bootstrap的jQuery多级列表树插件 treeview
http://www.cnblogs.com/mfc-itblog/p/5233453.html http://www.htmleaf.com/jQuery/Menu-Navigation/20150 ...