codeforces-1131 (div2)
A.把右上角的凹缺口补上变成凸的就成了规则矩形
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int main(){
LL w1,h1,w2,h2;
scanf("%lld%lld%lld%lld",&w1,&h1,&w2,&h2);
LL ans = w1 + w1 + h1 + h1 + h2 + h2 + ;
Prl(ans);
return ;
}
A
B.画在图上就是两条斜线之间有多少可以水平的线,显然是下面这条线的最高点和上面这条线的最低点作差,记得打一个vis标记记录哪些线取过了
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int main(){
Sca(N);
LL la = ,lb = ;
LL ans = ;
LL now = ;
for(int i = ; i <= N ; i ++){
LL a,b; scanf("%lld%lld",&a,&b);
int t = max(max(la,lb),now);
if(min(a,b) >= t){
ans += min(a,b) - t + ;
now = min(a,b) + ;
}
la = a; lb = b;
}
Prl(ans);
return ;
}
B
C.开始觉得要二分,后来觉得要O(n3),仔细一看发现O(n)
显然取两条非递减的线,从最高点往两边降低,贪心的发现每次都升高最高点更低的那个路径就可以了。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int b[maxn],c[maxn];
int main(){
Sca(N);
for(int i = ; i <= N ; i ++) Sca(a[i]);
sort(a + ,a + + N);
int cnt1 = ,cnt2 = ;
b[++cnt1] = a[];
c[++cnt2] = a[];
for(int i = ; i <= N ; i ++){
if(b[cnt1] < c[cnt2]) b[++cnt1] = a[i];
else c[++cnt2] = a[i];
}
for(int i = ; i <= cnt1; i ++) printf("%d ",b[i]);
for(int i = cnt2; i >= ; i --) printf("%d ",c[i]);
return ;
}
C
D.拓扑排序例题。
先把所有的等于号用并查集合并,找大小之间的冲突。然后用拓扑排序标记顺便判环。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
char MAP[maxn][maxn];
struct Edge{
int to,next;
}edge[maxn * maxn * ];
int fa[maxn * ],tot,head[maxn * ],ind[maxn * ];
void init(){
for(int i = ; i <= N + M; i ++){
head[i] = -;
fa[i] = i;
ind[i] = ;
}
tot = ;
}
void add(int u,int v){
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
}
int find(int x){
if(x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
void Union(int a,int b){
a = find(a); b = find(b);
fa[a] = b;
}
int ans[maxn];
int main(){
Sca2(N,M); init();
bool flag = ;
for(int i = ; i <= N ; i ++){
scanf("%s",MAP[i] + );
for(int j = ; j <= M ; j ++){
if(MAP[i][j] == '='){
Union(i,j + N);
}
}
}
for(int i = ; i <= N && flag; i ++){
for(int j = ; j <= M ; j ++){
if(MAP[i][j] == '=') continue;
int a = find(i),b = find(j + N);
if(a == b){
flag = ;
break;
}
if(MAP[i][j] == '>'){
add(b,a); ind[a]++;
}else{
add(a,b); ind[b]++;
}
}
}
if(!flag){
puts("No");
return ;
}
queue<int>Q;
for(int i = ; i <= N + M; i ++){
if(find(i) == i && !ind[i]){
ans[i] = ;
Q.push(i);
}
}
while(!Q.empty()){
int u = Q.front(); Q.pop();
for(int i = head[u]; ~i; i = edge[i].next){
int v = edge[i].to;
ans[v] = max(ans[v],ans[u] + );
ind[v]--;
if(!ind[v]) Q.push(v);
}
}
for(int i = ; i <= N + M; i ++){
if(fa[i] == i && ind[i]) flag = ;
}
if(!flag){
puts("No");
return ;
}
puts("Yes");
for(int i = ; i <= N ; i ++){
printf("%d ",ans[find(i)]);
}
puts("");
for(int j = N + ; j <= N + M; j ++){
printf("%d ",ans[find(j)]);
}
return ;
}
D
E.dp[100000][30]记录到i这个字符串j的最长长度。
如果右边的字符串都为k,那么dp[i][j] = max(dp[i][j],len * (dp[i - 1][j] + 1) + dp[i - 1][j]);
否则字符就变为前后缀与他相同的最长长度相加
如果曾经出现过这个字符,这个字符的出现次数至少为1
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 1e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
LL ans[];
LL dp[maxn][];
LL pre[];
LL tmp[];
char str[];
int main(){
Sca(N);
for(int i = ; i <= N ; i ++){
scanf("%s",str);
LL len = strlen(str);
LL a = ,b = len;
for(int j = ; j < ; j ++) tmp[j] = ;
for(int j = ; j < len; j ++){
if(j && str[j - ] == str[j]) pre[j] = pre[j - ] + ;
else pre[j] = ;
tmp[str[j] - 'a'] = max(tmp[str[j] - 'a'],pre[j]);
}
for(int j = ; j < ; j ++){
dp[i][j] = tmp[j];
int l = ,r = len - ;
while(l <= r && str[l] == j + 'a') l++;
while(r > l && j + 'a' == str[r]) r--;
if(l == len){
dp[i][j] = max(dp[i][j],len * (dp[i - ][j] + ) + dp[i - ][j]);
}else if(dp[i - ][j]){
dp[i][j] = max(dp[i][j],l + len - r);
}
}
}
LL sum = ;
for(int j = ; j < ; j ++) sum = max(sum,dp[N][j]);
Prl(sum);
return ;
}
E
F.喜闻乐见的送分F题,开到就是赚到。
并查集模板题,加一个l[maxn],r[maxn]表示这个集合最左最右的数字
nxt[maxn]表示这个数字的下一个数字,每次匹配u,v都把u集合放在v集合的左边,更新一下几个数组
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int fa[maxn],r[maxn],l[maxn];
int nxt[maxn];
void init(){
for(int i = ; i <= N ; i ++){
fa[i] = r[i] = l[i] = i;
nxt[i] = -;
}
}
int find(int x){
if(x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
int main(){
Sca(N); init();
for(int i = ; i <= N - ; i ++){
int u,v; Sca2(u,v);
u = find(u); v = find(v);
nxt[r[u]] = l[v];
l[v] = l[u];
fa[u] = v;
}
int root = l[find()];
for(int i = ; i <= N ; i ++){
printf("%d ",root);
root = nxt[root];
}
return ;
}
F
codeforces-1131 (div2)的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- Codeforces 1131 (div 2)
链接:http://codeforces.com/contest/1131 A Sea Battle 利用良心出题人给出的图,不难看出答案为\(2*(h1+h2)+2*max(w1,w2)+4\)由于 ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- 基于Odoo框架的开源在线客服系统
cs_base 开源客服系统,基于 Odoo 的客服模块 cs_base 是在强大的 Odoo 框架的基础上实现的一个在线客服应用 基础模块包含完整的 Web 在线客服的接入,坐席管理等,通过扩展可方 ...
- android添加阴影
android底部增加背景 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns: ...
- 【已采纳】charles工具使用心得
1.下载charles 可以去charles官网下载,下载地址:http://www.charlesproxy.com/download/ 根据自己的操作系统下载对应的版本,然后进行安装,然后打 ...
- C#中++i与i++的区别
日常编程中经常用到++i与i++,知识点虽然很小,但有时候会犯迷糊,在这里小小的记录一下. ++i 即前递增,顾名思义也就是先自增后传值: 举个栗子 int i=5; int j=++i; 此时i的值 ...
- django 问题综合
orm部分 本篇文章我会持续更新,把开发中遇到的一切orm相关的问题都放在这里 mysql索引报错 使用django 的orm,数据库用的mysql,在使用makemigrations和migrate ...
- SQL Server数据库————增删改查
--增删改查--增 insert into 表名(列名) value(值列表) --删 delect from 表名 where 条件 --改 update 表名 set 列名=值1,列名2=值2 w ...
- Docker: Jenkins里的pipeline编写基本技巧
Jenkins里,先新建一个pipeline项目 Pipeline Syntax 在Sample Step里选择需要的插件,如果不存在,就去系统管理,插件管理里,进行安装. 如果源码管理工具用的是gi ...
- js 秒数格式化
function formatSeconds(value) { var theTime = parseInt(value);// 秒 var theTime1 = 0;// 分 var theTime ...
- [LeetCode] 17. 电话号码的字母组合
题目描述:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/ 题目描述: 给定一个仅包含数字 2-9 的字符 ...
- [认证授权] 4.OIDC(OpenId Connect)身份认证(核心部分)
1 什么是OIDC? 看一下官方的介绍(http://openid.net/connect/): OpenID Connect 1.0 is a simple identity layer on to ...