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. Android为TV端助力:adb查找包名位置

    logcat | grep START 查找启动launcher adb shell "pm list packages -f | grep +包名" 查找包的路径

  2. WPF:Webbrowser 捕获关闭事件

    有点难描述说的是什么.大概就是下面这个图:窗体中嵌套一个Webbrowser,现在网页请求关闭 响应MessageHook事件: this.webBrowser.MessageHook += webB ...

  3. 简单的纯js三级联动

    参考这个  日尼禾尔  二级联动 写了三级联动 <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  4. C# 获取当前服务器域名

    "http://"是协议名 "www.test.com"是域名 "aaa"是站点名 "bbb.aspx"是页面名(文件名 ...

  5. Tomcat设置cmd窗口的title属性

    说明:官网下载tomcat之后,双击bin目录下的startup.bat文件,即可运行tomcat:linux下面运行startup.sh. 但是如果测试服务器上面搭建了多个项目,则启动之后窗口一样, ...

  6. MYSQL如何通过一张表更新另外一张表?

    1.背景说明 很多时候我们需要通过一张中间表的数据去更新另外一张表,而不仅仅是通过固定数值去更新,尤其是当数据量很大的时候,简单的复制粘贴就不大可行了. 2.MYSQL版本 SELECT VERSIO ...

  7. 记录display:table的使用

    兼容性:不兼容IE7 1.左右对齐 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...

  8. 记录Nginx作为静态资源web服务场景配置

    server { listen   80; server_name    localhost; sendfile    on; access_log    /var/log/nginx/host.ac ...

  9. 《JAVA程序设计》_第六周学习总结

    一.本周学习内容 1.内部类--7.1知识 在一个类的内部定义的类成为内部类,包含内部类的类叫做外嵌类 内部类和外嵌类的关系 外嵌类的成员变量在内部类中仍然有效,内部类也可调用外嵌类中的方法 内部类的 ...

  10. 基于jQuery实现简单的js模块化

    在多人合作完成网页,经常遇到大家的js代码相互影响的问题.现在有许多模块化的前端框架,应该是可以解决这个问题.但本人并非前端开发人员,那些框架都没用过,只对jQuery相对熟悉,就想用jQuery来解 ...