2.2.2017 9:35~11:35


A - Taymyr is calling you

直接模拟

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1e4+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,m,z,ans;
int vis[N];
int main(int argc, const char * argv[]) {
n=read();m=read();z=read();
for(int i=n;i<=z;i+=n) vis[i]=;
for(int i=m;i<=z;i+=m) ans+=vis[i];
printf("%d",ans);
return ;
}

B - Timofey and cubes

奇数位置反转,偶数位置不变

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=2e5+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,a[N];
int main(int argc, const char * argv[]) {
n=read();
for(int i=;i<=n;i++) a[i]=read();
for(int i=;i<=n/;i++) if(i&) swap(a[i],a[n-i+]);
for(int i=;i<=n;i++) printf("%d ",a[i]);
return ;
}

C - Timofey and a tree

题意:选一个根使得所有子树同色(每个子树中节点同色 不同子树可以不同色)

比赛时先打了个傻逼树形DP发现不对  然后就用对于一个点i它的子树用树形DP,它的上面的树用DFS序+线段树/ST表询问颜色相同......反正A掉了

//
// main.cpp
// C
//
// Created by Candy on 2017/2/2.
// Copyright © 2017年 Candy. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
#define mid ((l+r)>>1)
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
#define lc x<<1
#define rc x<<1|1
typedef long long ll;
const int N=2e5+;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,u,v,c[N],a[N];
struct edge{
int v,ne;
}e[N<<];
int h[N],cnt=;
inline void ins(int u,int v){
cnt++;
e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
cnt++;
e[cnt].v=u;e[cnt].ne=h[v];h[v]=cnt;
}
struct node{
int same;
}t[N<<];
void build(int x,int l,int r){
if(l==r) t[x].same=a[l];
else{
build(lson);
build(rson);
if(t[lc].same==||t[rc].same==||t[lc].same!=t[rc].same) t[x].same=;
else t[x].same=t[lc].same;
}
}
int segSame(int x,int l,int r,int ql,int qr){
if(ql>qr) return -;
if(t[x].same) return t[x].same;
if(ql<=l&&r<=qr) return t[x].same;
else{
int same=-;
if(ql<=mid) same=segSame(lson,ql,qr);
if(mid<qr){
int _=segSame(rson,ql,qr);
if(same==-||same==_) same=_;
else same=;
}
return same;
}
}
int d[N],L[N],R[N],dfc;
void dfs(int u,int fa){
L[u]=++dfc; a[dfc]=c[u];
d[u]=c[u];
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v;
if(v==fa) continue;
dfs(v,u);
if(d[u]!=&&d[v]!=d[u]) d[u]=;
}
R[u]=dfc;
}
int ans;
void dfsSol(int u,int fa){//printf("dfsSol %d %d\n",u,fa);
if(ans) return;
int flag=;
for(int i=h[u];i;i=e[i].ne) if(e[i].v!=fa)
if(d[e[i].v]==) {flag=;break;}
if(flag){
int s1=segSame(,,n,,L[u]-),s2=segSame(,,n,R[u]+,n);
flag=;
if(s1!=&&s2!=&&(s1==-||s2==-||s1==s2)) flag=;
// printf("hi %d %d %d %d %d %d\n",u,L[u],R[u],s1,s2,flag);
if(flag) {ans=u;return;}
} for(int i=h[u];i;i=e[i].ne)
if(e[i].v!=fa) dfsSol(e[i].v,u);
}
int main(int argc, const char * argv[]) {
n=read();
for(int i=;i<=n-;i++) u=read(),v=read(),ins(u,v);
for(int i=;i<=n;i++) c[i]=read();
dfs(,);
build(,,n);
// for(int i=1;i<=n;i++) printf("hi %d %d %d %d\n",i,d[i],L[i],R[i]);
// for(int i=1;i<=n;i++) printf("a %d %d\n",i,a[i]);
dfsSol(,);
if(ans) printf("YES\n%d",ans);
else puts("NO");
return ;
}

比赛代码

实际上可以发现如果一条边两边节点的颜色不对一定是这两个节点中的一个做根,三遍DFS就行了....好简单

dfs

D - Timofey and rectangles

题意:一些不相交矩形边长都是奇数 4种颜色染色 判断可行及一种方案

....最后才看到洛谷群有这道题题解然后最后10s提交失败呜呜呜

超简单 边长奇数,所以横边相邻的矩形y坐标奇偶性不同 x同理 所以按左下角奇偶性染色就行了

//
// main.cpp
// C
//
// Created by Candy on 2017/2/2.
// Copyright © 2017年 Candy. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,x,y;
int main(int argc, const char * argv[]) {
n=read();
puts("YES");
for(int i=;i<=n;i++){
x=read();y=read();
x=min(x,read());y=min(y,read());
x+=1e9;y+=1e9;
if(x&){
if(y&) puts("");
else puts("");
}else{
if(y&) puts("");
else puts("");
}
}
}

未完

Codeforces Round #395 (Div. 2)(未完)的更多相关文章

  1. Codeforces Round #395 (Div. 2)(A.思维,B,水)

    A. Taymyr is calling you time limit per test:1 second memory limit per test:256 megabytes input:stan ...

  2. Codeforces Round #395 (Div. 2) D. Timofey and rectangles

    地址:http://codeforces.com/contest/764/problem/D 题目: D. Timofey and rectangles time limit per test 2 s ...

  3. Codeforces Round #395 (Div. 2) C. Timofey and a tree

    地址:http://codeforces.com/contest/764/problem/C 题目: C. Timofey and a tree time limit per test 2 secon ...

  4. Codeforces Round #395 (Div. 2)B. Timofey and cubes

    地址:http://codeforces.com/contest/764/problem/B 题目: B. Timofey and cubes time limit per test 1 second ...

  5. Codeforces Round #395 (Div. 1)

    比赛链接:http://codeforces.com/contest/763 A题: #include <iostream> #include <cstdio> #includ ...

  6. Codeforces Round #395 (Div. 2)

    今天自己模拟了一套题,只写出两道来,第三道时间到了过了几分钟才写出来,啊,太菜了. A. Taymyr is calling you 水题,问你在z范围内  两个序列  n,2*n,3*n...... ...

  7. 【分类讨论】Codeforces Round #395 (Div. 2) D. Timofey and rectangles

    D题: 题目思路:给你n个不想交的矩形并别边长为奇数(很有用)问你可以可以只用四种颜色给n个矩形染色使得相接触的 矩形的颜色不相同,我们首先考虑可不可能,我们分析下最多有几个矩形互相接触,两个时可以都 ...

  8. 【树形DP】Codeforces Round #395 (Div. 2) C. Timofey and a tree

    标题写的树形DP是瞎扯的. 先把1看作根. 预处理出f[i]表示以i为根的子树是什么颜色,如果是杂色的话,就是0. 然后从根节点开始转移,转移到某个子节点时,如果其子节点都是纯色,并且它上面的那一坨结 ...

  9. Codeforces Round #395 (Div. 2) C

    题意 : 给出一颗树 每个点都有一个颜色 选一个点作为根节点 使它的子树各自纯色 我想到了缩点后check直径 当<=3的时候可能有解 12必定有解 3的时候需要check直径中点的组成点里是否 ...

随机推荐

  1. msf

    show exploit show payload msf使用数据库加快搜索,不然每次都等半天 service postgresql startmsfdb reinitmsf > db_rebu ...

  2. event.target与event.srcElement

    target 事件属性可返回事件的目标节点(触发该事件的节点),如生成事件的元素.文档或窗口. 在标准浏览器下我们一般使用event.target就能解决,然而低版本IE浏览器总是会出些幺蛾子,这时候 ...

  3. Java-String.intern的深入研究

    When---什么时候需要了解String的intern方法: 面试的时候(蜜汁尴尬)!虽然不想承认,不过面试的时候经常碰到这种高逼格的问题来考察我们是否真正理解了String的不可变性.String ...

  4. console.log()的作用是什么

    主要是方便你调式javascript用的.你可以看到你在页面中输出的内容. 相比alert他的优点是: 他能看到结构话的东西,如果是alert,淡出一个对象就是[object object],但是co ...

  5. 【JDBC】Java 连接 MySQL 基本过程以及封装数据库工具类

    一. 常用的JDBC API 1. DriverManager类 : 数据库管理类,用于管理一组JDBC驱动程序的基本服务.应用程序和数据库之间可以通过此类建立连接.常用的静态方法如下 static ...

  6. log4j配置文件简要记录

    和大多数配置文件一样,log4j配置文件也有key-value形式和xml形式.这里主要记录一下key-value的形式 我们通过配置,可以创建出Log4j的运行环境.Log4j由三个重要的组件构成: ...

  7. 邓_ Php·笔记本[照片]

    -------------------------------------------------------------------------------------------- [PHP] - ...

  8. asp.net -mvc框架复习(9)-实现用户登录控制器和视图的编写并调试

    1.编写控制器 三个步骤: [1]获取数据 [2]业务处理 [3]返回数据 using System;using System.Collections.Generic;using System.Lin ...

  9. MapReduce 原理与 Python 实践

    MapReduce 原理与 Python 实践 1. MapReduce 原理 以下是个人在MongoDB和Redis实际应用中总结的Map-Reduce的理解 Hadoop 的 MapReduce ...

  10. Number()和new Number()的区别以及一种简单实现

    看MDN Beginners文档的时候注意到了这种用法 var n1 = Number(123); , 冒出的第一个疑问就是和 var n2 = new Number(123); 有什么区别呢? 首先 ...