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. laravel 5.6

    compact() 建立一个数组,包括变量名和它们的值 打印结果: starts_with() 函数判断给定的字符串的开头是否是指定值

  2. spring-data-mongo的MongoTemplate开发

    spring-data-mongo的MongoTemplate开发 1.在实体类Customer.Java中引入注解表明转换方式 @Document   //文档 public class Custo ...

  3. C++ Primer 笔记——动态数组

    1.动态数组定义时也需要指明数组的大小,但是可以不是常量. int i; int arr[i]; // 错误,数组的大小必须为常量 int *p = new int[i]; // 正确,大小不必是常量 ...

  4. tomcat安装出现的闪退问题

    如果闪退 在该文件中结尾添加pause  可以检测到路径问题是不是有问题

  5. Mom and Dad

    Mom  Poodwaddle Life clock Dad Poodwaddlw Life clock Happiness is the meaning and the purpose of lif ...

  6. node.js vue-axios和vue-resource

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. RabbitMQ三种Exchange模式(fanout,direct,topic)的性能比较

    RabbitMQ中,所有生产者提交的消息都由Exchange来接受,然后Exchange按照特定的策略转发到Queue进行存储 RabbitMQ提供了四种Exchange:fanout,direct, ...

  8. poj2398

    题解: 计算几何入门题 对每个二分最近的在它右边的杆子 如何判断一个杆子在它右边呢 计算机判断这些要更善于利用点积和叉积 如果叉积为正代表在顺时针方向叉积为负在逆时针 发现要在struct里面重载运算 ...

  9. redis 配置命令

    Redis:是一个key/v  型数据 是nosql的一种 CAP 理论: C:多个数据节点上的数据一致: A:用户发出请求后的有限时间范围内返回结果: P:network partition,网络发 ...

  10. Python学习(十二) —— 面向对象

    一.初识面向对象 面向过程的核心是过程,流水线思维,过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西. 优点:极大地降低了写程序的复杂度,只需要顺着要执行的 ...