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 ...
随机推荐
- java-HTML&javaSkcript&CSS&jQuery&ajax
CSS 伪装 1.<style>a;link{color:#000000} a:visited{color:#000000; a.:hover{color:#FF00FF} a:acti ...
- Python+selenium自动化测试中Windows窗口跳转方法
Python+selenium自动化测试中Windows窗口跳转方法 #第一种方法 #获得当前窗口 nowhandle=driver.current_window_handle #打开弹窗 drive ...
- 史上最简单的 SpringCloud 教程 | 第一篇: 服务的注册与发现(Eureka)
一.spring cloud简介 spring cloud 为开发人员提供了快速构建分布式系统的一些工具,包括配置管理.服务发现.断路器.路由.微代理.事件总线.全局锁.决策竞选.分布式会话等等.它运 ...
- Python自定义排序
比如自定义了一个class,并且实例化了这个类的很多个实例,并且组成一个数组.这个数组要排序,是通过这个class的某个字段来排序的.怎么排序呢? 有两种做法: 第一种是定义__cmp__( )方法: ...
- .Net页面缓存OutPutCache详解
一 它在Web.Config中的位置 <system.web> <!--页面缓存--> <caching> <outputCacheSettings> ...
- tp3.2上传图片生成缩略图
//引入 use think\Image; /* * $name为表单上传的name值 * $filePath为为保存在入口文件夹public下面uploads/下面的文件夹名称,没有的话会自动创建 ...
- Log4Net帮助类
工具类 using System; using System.Diagnostics; using log4net; namespace Trumgu_BI_PF.Util { public clas ...
- $_FILES["file"]["error"]是错误代码
$_FILES["file"]["error"]是错误代码,0表示没有错误,下面几种对应不同的错误1 : 上传的文件超过了 php.ini 中 upload_m ...
- BZOJ 1706
题解: 倍增+floyd 首先这题比较容易想到是把每个点拆点做dij 但是这样复杂度是knlogn的 这道题的k较大,所以不行 我们考虑到每走一步,其实就是在进行一次floyd 而这个可以看成矩阵乘法 ...
- sparkStreaming消费kafka-0.8方式:direct方式(存储offset到zookeeper)
生产中,为了保证kafka的offset的安全性,并且防止丢失数据现象,会手动维护偏移量(offset) 版本:kafka:0.8 其中需要注意的点: 1:获取zookeeper记录的分区偏移量 2: ...