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

  1. 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++ ...

  2. 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/ ...

  3. 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 ...

  4. Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)

    https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...

  5. Codeforces Round #517 (Div. 2)(1~n的分配)

    题:https://codeforces.com/contest/1072/problem/C 思路:首先找到最大的x,使得x*(x+1)/2 <= a+b 那么一定存在一种分割使得 a1 &l ...

  6. Codeforces Round #517 Div. 2/Div. 1

    \(n\)天没更博了,因为被膜你赛的毒瘤题虐哭了... 既然打了这次CF还是纪念一下. 看看NOIP之前,接下来几场的时间都不好.这应该是最后一场CF了,差\(4\)分上紫也是一个遗憾吧. A 给一个 ...

  7. Codeforces Round #517 Div. 1翻车记

    A:真的懵逼了.冷静了半天之后决定二分一下答案,然后先a安排上尽量小的再贪心地一个个扩大.40min才过.这个做法非常怂的以代码复杂度和时间复杂度为代价换取了比较稳的正确性,事实上由于1~n可以组合出 ...

  8. 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] ...

  9. 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 ...

随机推荐

  1. 小LK玩积木

    小LK玩积木 时间限制: 1 Sec  内存限制: 128 MB 题目描述 HH最近通过黑洞APP下载了一个盗梦APP,据说能进入一个人的梦里做一些嘿嘿嘿的事情,秉着怀疑的态度HH偷偷地潜入LK的梦中 ...

  2. JavaScript 高级程序设计第二版

    20.4 部署 20.4.1 构建 构建过程始于在源控制中定义用于存储文件的逻辑结构.最好避免使用一个文件存放所有的JavaScript,遵循以下面向对象语言中的典型模式:将每个对象或自定义了类别分别 ...

  3. 20165206 2017-2018-2 《Java程序设计》第七周学习总结

    20165206 2017-2018-2 <Java程序设计>第七周学习总结 教材学习内容总结 MySqL:是世界上最流行的开源数据管理系统. 配置启动MySQL. 连接数据库:Conne ...

  4. OpenCV-Python入门教程2-打开摄像头

    一.打开摄像头 import cv2 # 打开摄像头并灰度化显示 capture = cv2.VideoCapture(0) while(True): # 获取一帧 ret, frame = capt ...

  5. hive和hbase比较(整理)

    hive1.可以理解为一种SQL执行引擎,对SQL的支持最终转换为map/reduce任务2.不支持更新.删除操作,但可以插入3.任务不是实时执行,用时一般为数分钟到数小时4.本身可以不存储数据,只存 ...

  6. UPC 6616 Small Mulitple

    D - Small Multiple 题目传送门 Time limit : 2sec / Memory limit : 256MB Score : 700 points Problem Stateme ...

  7. [转] UniCode编码表

    Unicode编码则是采用双字节16位来进行编号,可编65536字符,基本上包含了世界上所有的语言字符,它也就成为了全世界一种通用的编码,而且用十六进制4位表示一个编码,非常简结直观,为大多数开发者所 ...

  8. html5 之 local storage \sessjion storage

    转载: HTMl5的sessionStorage和localStorage html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. sessi ...

  9. javascript 正则表达式(十)

    一.什么是正则 在常见的字符串检索和替换中,我们需要提供一种模式表示检索或替换的规则.正则表达式使用单个字符串来描述.匹配一系列符合某个句法规则的字符串. abc [a-z]{4} \d\d\d 二. ...

  10. 10本Java架构师必读书籍

    1.大型网站系统与JAVA中间件实践 本书围绕大型网站和支撑大型网站架构的Java中间件的实践展开介绍. 从分布式系统的知识切入,让读者对分布式系统有基本的了解:然后介绍大型网站随着数据量.访问量增长 ...