版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/yew1eb/article/details/25609981

A Points and Segments (easy)

 智商题。(智商捉急~)

/***********************************************************
*分析:仅仅要按Xi从小到大染成1010101010... ,
*1、0间隔的的序列就能保证对于随意区间[l, r]中1的个数和0的个数之差小于等于1。
*注意:因为输入的Xi可能是无序的。全部要两次排序处理。
**********************************************************/
#include <cstdio>
#include <algorithm>
using namespace std; const int maxn = 200 + 5; struct node {
int id;
int x;
int val;
};
node a[maxn];
int n, m; bool cmp_x(const node &a,const node &b)
{
return a.x < b.x;
}
bool cmp_id(const node &a,const node &b)
{
return a.id<b.id;
}
int main()
{
int i, l, r;
scanf("%d%d",&n,&m);
for(i=0; i<n; ++i)
{
scanf("%d",&a[i].x);
a[i].id = i;
}
for(i=0; i<m; ++i)
scanf("%d%d",&l, &r);
sort(a, a + n, cmp_x);
for(i=0; i<n; ++i)
a[i].val = i&1;
sort(a, a + n, cmp_id);
for(i=0; i<n; ++i)
printf("%d ", a[i].val); return 0;
}

B Balls Game

枚举

/************************************************
*分析:枚举插入点,然后用循环模拟消除操作
************************************************/
#include <stdio.h>
int n, k, x;
int a[100+5]; int main()
{
int i, l, r, cnt, ret, ans = 0;
scanf("%d%d%d",&n, &k, &x);
for(i=0; i<n; ++i)
scanf("%d",&a[i]); for(i=0; i<n; ++i)
if(a[i]==x)
{
l = r = i;
cnt = 0;
while(a[l] == a[r])
{
ret = 2;
while(l > 0 && a[l-1] == a[l]) { l--; ret++;}
while(r < n-1 && a[r+1] == a[r]) {r++; ret++;}
--l; ++r;
if(ret<3) break;
cnt += ret;
if(l < 0 || r >= n) break;
}
if(cnt-1 > ans) ans = cnt-1;
}
printf("%d\n", ans);
return 0;
}

C Xor-tree

建树后DFS

/******************************
* 分析:题意简单
* 在树上进行简单的操作
******************************/
#include <cstdio>
#include <vector>
using namespace std; const int maxn = 100000 + 10;
vector<int> Edge[maxn];
int cnt = 0, ans[maxn];
int n, a[maxn], b[maxn]; void dfs(int rt, int pre, int p1, int p2)
{
if( a[rt]^ p1 != b[rt])
{
ans[cnt++] = rt;
p1 = 1- p1;
} for(int i=0; i<Edge[rt].size(); ++i)
{
int &e = Edge[rt][i];
if(e == pre) continue;
dfs(e, rt, p2, p1);
}
} int main()
{
int i, x, y;
scanf("%d",&n);
for(i=1; i<n; ++i)
{
scanf("%d%d",&x,&y);
Edge[x].push_back(y);
Edge[y].push_back(x);
}
for(i=1; i<=n; ++ i) scanf("%d",&a[i]); for(i=1; i<=n; ++i) scanf("%d",&b[i]);
dfs(1, -1, 0, 0);
printf("%d\n", cnt);
for(i=0; i<cnt; ++i)
printf("%d\n", ans[i]);
return 0;
}

D Working out

先递推出每个点(i,j)到四个顶点{(n,m), (n,1), (1,m), (1,1) }的最大权值和。 然后枚举交点。 对于每个交点仅仅有例如以下图两种情况满足题意仅仅有一个交点。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveWV3MWVi/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />

#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1000 + 100;
int n, m, a[maxn][maxn], f1[maxn][maxn], f2[maxn][maxn], f3[maxn][maxn], f4[maxn][maxn], ans; int main()
{
int i, j;
scanf("%d%d",&n, &m);
for(i=1; i<=n; ++i)
for(j=1; j<=m; ++j)
scanf("%d",&a[i][j]); for(i=1; i<=n; ++i)
for(j=1; j<=m; ++j)
f1[i][j] = max(f1[i-1][j], f1[i][j-1]) + a[i][j]; for(i=1; i<=n; ++i)
for(j=m; j>=1; --j)
f2[i][j] = max(f2[i][j+1], f2[i-1][j]) + a[i][j]; for(i=n; i>=1; --i)
for(j=1; j<=m; ++j)
f3[i][j] = max(f3[i][j-1], f3[i+1][j]) + a[i][j]; for(i=n; i>=1; --i)
for(j=m; j>=1; --j)
f4[i][j] = max(f4[i][j+1], f4[i+1][j]) + a[i][j]; ans = 0;
for(i=2; i<n; ++i)
for(j=2; j<m; ++j)
ans = max(ans, max(f1[i-1][j] + f2[i][j+1] + f3[i][j-1] + f4[i+1][j],
f1[i][j-1] + f2[i-1][j] + f3[i+1][j] + f4[i][j+1]) );
printf("%d\n", ans);
return 0;
}

E Guess the Tree

load....

Codeforces Round #245 (Div. 2)的更多相关文章

  1. Codeforces Round #245 (Div. 1) 429D - Tricky Function 最近点对

    D. Tricky Function Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/42 ...

  2. Codeforces Round #245 (Div. 1) B. Working out (简单DP)

    题目链接:http://codeforces.com/problemset/problem/429/B 给你一个矩阵,一个人从(1, 1) ->(n, m),只能向下或者向右: 一个人从(n, ...

  3. Codeforces Round #245 (Div. 1) B. Working out (dp)

    题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...

  4. Codeforces Round #245 (Div. 1) B. Working out dp

    题目链接: http://codeforces.com/contest/429/problem/B B. Working out time limit per test2 secondsmemory ...

  5. Codeforces Round #245 (Div. 2) C. Xor-tree DFS

    C. Xor-tree Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem/C ...

  6. Codeforces Round #245 (Div. 2) B. Balls Game 并查集

    B. Balls Game Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem ...

  7. Codeforces Round #245 (Div. 2) A. Points and Segments (easy) 贪心

    A. Points and Segments (easy) Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/con ...

  8. Codeforces 429 B. Working out-dp( Codeforces Round #245 (Div. 1))

    B. Working out time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #245 (Div. 2) B - Balls Game

    暴利搜索即可 #include <iostream> #include <vector> #include <iostream> using namespace s ...

  10. Codeforces Round #245 (Div. 2) A - Points and Segments (easy)

    水到家了 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

随机推荐

  1. .Net Core Cors中间件解析

    一.同源策略和资源跨域共享 1.同源策略 同源策略,它是由Netscape提出的一个著名的安全策略.现在所有支持JavaScript 的浏览器都会使用这个策略.所谓同源是指,域名,协议,端口相同. 1 ...

  2. Oracle 连接到RMAN

    set oracle_sid=orcl rman connect target sys/password@orcl;

  3. TCP/IP 详解

    分层 每一层负责不同的功能:     链路层 有时也称作数据链路层或网络接口层, 通常包括操作系统中的设备驱动程序和计算机 中对应的网络接口卡.它们一起处理与电缆(或其他任何传输媒介)的物理接口细节. ...

  4. Struts2框架笔记02_API_结果页面配置_数据的封装

    目录 1. Struts2的Servlet的API的访问 1.1 方式一:完全解耦合的方式 1.1.1 环境搭建 1.1.2 代码 1.1.3 测试 1.1.4 向域对象中存入数据 1.2 方式二:使 ...

  5. Mybatis关联查询之一对多和多对一XML配置详解

    平时在开发过程中dao.bean和XML文件都是自动生成的,很少写XML的配置关系,今天记录一下mybatis的关联查询中的多对一和一对多的情况. 首先是有两张表(学生表Student和老师Teach ...

  6. blfs(systemv版本)学习笔记-配置远程连接显示中文

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 远程连接的lfs系统需要具备以下环境便可在xshell或其他远程终端上面显示中文: 1.lfs主机设置中文编码(需要配置) 2. ...

  7. Java执行sh等

    1.通过java代码,调用bat.shell等脚本或者命令 1)使用Runtime的exec()方法,会返回一个用于管理操作系统进程的Process对象 Process process =null; ...

  8. loadsh常用函数

    此篇文章会记录常用的lodash函数 防抖函数:_.debounce() 创建一个去缓冲函数,该函数将自上次调用函数以来经过设置的等待毫秒后调用func. 去缓冲函数带有一个取消方法来取消延迟的fun ...

  9. 纯css实现元素下出现横线动画(background-image)

    效果图: html: <div class='site_bar'>首页</div> css: .site_bar{ background-image : linear-grad ...

  10. chrome 远程调试相关问题

    1.使用chrome remote debug时打开inspect时出现一片空白 2.如何不用FQ可以享受Chrome for android的远程调试功能 3.chrome://appcache-i ...