版权声明:本文为博主原创文章,未经博主同意不得转载。 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. netty源码解解析(4.0)-3 Channel的抽象实现

    AbstractChannel和AbstractUnsafe抽象类 io.netty.channel.AbstractChannel 从本章开始,会有大量的篇幅涉及到代码分析.为了能够清晰简洁的地说明 ...

  2. python装饰器带括号和不带括号的语法和用法

    装饰器的写法补充: 通常装饰器的写法是@func(),而有的时候为了减少出错率,可能会写成@func,没有()括号,这时我们可以这样定义,来减少括号.下面通过两个例子还看. 一般装饰器的写法: def ...

  3. VB.NET语法小结

    本人精通C#编程,VB没有开发经验,项目维护需要,特意整理了下VB语法,进行恶补.编程思想都是互通的,都是微软生的,语言大同小异. Imports System 一.(1)定义一个变量,并且初始化. ...

  4. LeetCode算法笔记目录

    贪心算法: LeetCode翻转矩阵后的得分-Python3<六> LeetCode根据身高重建队列-Python3<七> LeetCode 任务调度器-Python3< ...

  5. appendChild简单表格的增删改查

    ---恢复内容开始--- <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><hea ...

  6. Maven的pom.xml文件详解【转载】

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  7. HDU4287

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. blfs(systemv版本)学习笔记-编译安装i3-wm平铺式窗口管理器

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! i3-wm项目的官网:https://i3wm.org/ 首先需要lfs基础上编译安装完整的xorg服务 我的xorg服务编译安 ...

  9. curl 发送 post 请求

    curl -i -X POST -H 'Content-type':'application/json' -d '{"keyWord":"雅诗兰黛"," ...

  10. Python 练习:简单的购物车

    salary = int(input("Please input your salary: ")) msg = ''' 1. iphone6s 5800 2. mac book 9 ...