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. 【esri-loader】帮助文档翻译 part1 是什么,怎么安装,为什么要用它

    是什么 esri-loader是一个JavaScript库(包/模块,Web模块化编程的概念),用于在非Dojo框架的Web页面中加载ArcGIS API for JavaScript 3.x或4.x ...

  2. Snapde和常用的CSV文件编辑器对比

    Snapde,一个专门为编辑超大型数据量CSV文件而设计的单机版电子表格软件:它运行的速度非常快,反应非常灵敏. CSV是一种用逗号分隔列.回车分割行的文本文件,市面上常用的CSV编辑软件有:Snap ...

  3. Android远程桌面助手(B1309)

    修改了窗口缩放的处理,支持Android Car等非常规分辨率的Android设备: 修改了获取Android端软件版本的方法,优化了APK的升级逻辑: 优化了远程输入法功能,支持利用PC端输入法快速 ...

  4. 自己动手写事件总线(EventBus)

    本文由云+社区发表 事件总线核心逻辑的实现. EventBus的作用 Android中存在各种通信场景,如Activity之间的跳转,Activity与Fragment以及其他组件之间的交互,以及在某 ...

  5. 逻辑回归&线性支持向量机

    代码: # -*- coding: utf-8 -*- """ Created on Tue Jul 17 10:13:20 2018 @author: zhen &qu ...

  6. 对css盒模型的理解

    介绍一下标准css的盒子模型?低版本IE的盒子模型有什么不同的? 1.有两种:IE盒子模型(怪异模式).W3c盒子模型(标准模式). 2.盒模型组成:内容(content).内边距(padding). ...

  7. Powershell-创建Module

    1.找到默认module路径,ISE启动时自动加载默认领下的Module代码. $env:PSModulePath 2.在其中一个默认路径下创建个文件夹,在文件夹下创建一个.psm1后缀文件,注意文件 ...

  8. RabbitMQ框架构建系列(一)——AMPQ协议

    一.MQ 在介绍RabbitMq之前,先来说一下MQ.什么是MQ?MQ全称为Message Queue即消息队列,就是一个消息的容器, MQ是消费-生产者模型的一个典型的代表,一端往消息队列中不断写入 ...

  9. ASP.NET Core 下的依赖注入(一)

    本文介绍利用 Microsoft.Extensions.Configuration.Binder.dll 来实现超级简单的注入. 1. appsettings.json 中定义配置 假设我们有如下配置 ...

  10. 转:eclipse 设置Java快捷键补全

    1.打开Eclipse,点击" Window - Preferences"; 2. 在目录树上选择"Java——Editor——Content Assist", ...