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

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. Codeforces 1131 (div 2)

    链接:http://codeforces.com/contest/1131 A Sea Battle 利用良心出题人给出的图,不难看出答案为\(2*(h1+h2)+2*max(w1,w2)+4\)由于 ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  10. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. POST一下就知道:人生苦短,我用Python!

    Python编程笔记---- 背景: “闸机端”简版程序要求: 读取扫描仪得到的userID; 向服务器发送请求进行验证: 根据返回值(True/False)决定闸机的信号. 1. 文件的读取 网上买 ...

  2. 【English】七、常见动词

    一.动词: touch.hear.say.listen touch [tʌtʃ] 触摸 I touch the cat. They touch the elephant. hear  [hɪr] 听到 ...

  3. MySQL 基础知识梳理学习(七)----sync_binlog

    一般在生产环境中,很少用MySQL单实例来支撑业务,大部分的MySQL应用都是采用搭建集群的方法.搭建MySQL集群,可以进行数据库层面的读写分离.负载均衡或数据备份.基于MySQL原生的Replic ...

  4. Docker-单宿主机下的网络模式

    docker利用namespaces和cgroups实现了应用隔离和资源控制,那么网络层优势如何实现的呢?是直接使用宿主机的网卡设备,还是独立创造出自己的网络设备?以及容器如何与外界通信,下面我们通过 ...

  5. 移动端click延迟和tap事件

    一.click等事件在移动端的延迟 click事件在移动端和pc端均可以触发,但是在移动端有延迟现象. 1.背景 由于早期移动设备浏览网页时内容较小,为了增强用户体验,苹果公司专门为移动设备设计了双击 ...

  6. 解决FileZilla访问手机ftp服务只能删除浏览文件不能下载文件的问题

    用了Linux系统之后,很多资源都不方便获取, 因为很多资料都是放在百某某盘上面. 无意中看到我手机有FTP服务,想到我电脑装有FileZilla,可以访问手机了 然后就连接上了. 但是浏览的时候发现 ...

  7. Autoit 实现word拆分页解析 (python同理)

    Autoit 实现word拆分页解析 (python同理) 背景 之前一直在做相关工作,由于没有找到解决最佳解决方案,老办法思路是 python先将word 转成pdf,按照页码 提取文字,从而实现w ...

  8. Dora.Interception,为.NET Core度身打造的AOP框架 [1]:更加简练的编程体验

    很久之前开发了一个名为Dora.Interception的开源AOP框架(github地址:https://github.com/jiangjinnan/Dora,如果你觉得这个这框架还有那么一点价值 ...

  9. C语言之输入月收入,输出该月应纳税额-2019(简易版)

    #include<stdio.h> #include<stdlib.h> #include<string.h> #define s1 0.03 //税率b < ...

  10. Trie树(字典树)推荐文章

    Trie树也被称为字典树,通过这个名字,可以明显知道这种树的结构:像字典一样进行查找的树(想想采用拼音法查找汉字的时候的过程,实质上就是一个逐字母匹配的过程).Trie树就是利用了这种思想构造出来的多 ...