Codeforces Round #395 (Div. 2)
今天自己模拟了一套题,只写出两道来,第三道时间到了过了几分钟才写出来,啊,太菜了。
A. Taymyr is calling you
水题,问你在z范围内 两个序列 n,2*n,3*n...... 和 m,2*m,3*m.....有多少个是一样的。
#include<bits/stdc++.h>
using namespace std;
int n,m,z;
int main()
{
cin>>n>>m>>z;
int gcd=__gcd(n,m);
int now=n*m/gcd;
int ans=;
int res=now;
while(res<=z)
{
ans++;
res+=now;
}
cout<<ans<<endl;
return ;
}
B. Timofey and cubes
题目大意:给你n个数,进行(n/2)次操作,每次操作将制定区间里的数交换,给你交换后的
让你求原来的。
思路:水题,奇偶讨论。
#include<bits/stdc++.h>
const int N=*1e5+;
using namespace std;
int a[N];
int n;
int main()
{
cin>>n;
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int mid=n/;
int i=,j=n;
bool flag=true;
while(i<=j)
{
if(flag)
{
int t=a[i];
a[i]=a[j];
a[j]=t;
}
flag=!flag;
i++,j--;
}
for(int i=;i<=n;i++) printf("%d%c",a[i],i==n? '\n':' ');
return ;
}
C. Timofey and a tree
题目大意:给你一颗树,每个节点都有一个颜色,让你挑选一个节点当做整棵树的根,满足所有
子树中节点的颜色都是一样的。如果没有输出NO 否则输入YES 且输出选择的节点。
思路:刚开始的思路是我觉得这棵树中的颜色不能超过 3 种,后来一想这种想法好智障啊,明显
不对,后来枚举树根每个都dfs一下超时,结束后想我随便找一个点dfs找到两个相邻的颜色不同的
点,那么这两个点中间肯定有一个要当做树根的,否则不成立。这样只要dfs两次就行了。
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
vector<int> e[N];
int c[N],item1,item2,n;
map<int,bool> mp;
bool flag;
void dfs1(int u,int pre)
{
//printf("%d\n",u);
if(pre!=- && c[u]!=c[pre])
{
item1=u;
item2=pre;
return;
}
for(int i=;i<e[u].size();i++)
{
int to=e[u][i];
if(to!=pre) dfs1(to,u);
if(item1!=-) return;
}
}
void dfs(int u,int pre,int item)
{
// printf("%d %d %d**\n",u,pre,item);
if(pre!=item && pre!=- && c[u]!=c[pre])
{
flag=false;
return;
}
for(int i=;i<e[u].size();i++)
{
int to=e[u][i];
if(to!=pre) dfs(to,u,item);
if(!flag) return;
}
}
int main()
{
cin>>n;
for(int i=;i<n;i++)
{
int f,t;
scanf("%d%d",&f,&t);
e[f].push_back(t);
e[t].push_back(f);
}
int cnt=;
for(int i=;i<=n;i++) scanf("%d",&c[i]);
item1=-,item2=-;
dfs1(,-);
if(item1==-)
{
puts("YES");
puts("");
return ;
}
flag=true;
dfs(item1,-,item1);
if(flag)
{
puts("YES");
printf("%d\n",item1);
return ;
}
flag=true;
dfs(item2,-,item2);
if(flag)
{
puts("YES");
printf("%d\n",item2);
return ;
}
puts("NO");
return ;
}
D. Timofey and rectangles
题目大意:给你n个矩形,且矩形的边长为奇数,任意两个矩形都不相交,最多相邻,现在让你给这些矩形上色,
一种4种颜色,相邻的矩形颜色不能相等,问你有没有这样的方案,如果有则输出。
思路:赤裸裸的脑洞题,专门碾压我这种低智商的,这题最关键的是矩形的边长是奇数,虽然我知道,但是
我还是不会写QAQ。
首先,四个矩形不可能两两互相相邻,所以结论一定是YES
然后,我们考虑矩形的左下角的顶点,如果 x 和 y 的值都为奇数,因为边长是奇数,所以这个矩形不可能和
另一个左下角坐标都为奇数的矩形相邻。所以我们给这类矩形染色 1 。
其他三种同理。
#include<bits/stdc++.h>
using namespace std;
const int N=*1e5+;
int n,vis[N],m=1e9;
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if((x1+m)% && (y1+m)%) vis[i]=;
else if((x1+m)%) vis[i]=;
else if((y1+m)%) vis[i]=;
else vis[i]=;
}
cout<<"YES"<<endl;
for(int i=;i<=n;i++) printf("%d\n",vis[i]);
return ;
}
Codeforces Round #395 (Div. 2)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #395 (Div. 1)
比赛链接:http://codeforces.com/contest/763 A题: #include <iostream> #include <cstdio> #includ ...
- Codeforces Round #395 (Div. 2)(未完)
2.2.2017 9:35~11:35 A - Taymyr is calling you 直接模拟 #include <iostream> #include <cstdio> ...
- 【分类讨论】Codeforces Round #395 (Div. 2) D. Timofey and rectangles
D题: 题目思路:给你n个不想交的矩形并别边长为奇数(很有用)问你可以可以只用四种颜色给n个矩形染色使得相接触的 矩形的颜色不相同,我们首先考虑可不可能,我们分析下最多有几个矩形互相接触,两个时可以都 ...
- 【树形DP】Codeforces Round #395 (Div. 2) C. Timofey and a tree
标题写的树形DP是瞎扯的. 先把1看作根. 预处理出f[i]表示以i为根的子树是什么颜色,如果是杂色的话,就是0. 然后从根节点开始转移,转移到某个子节点时,如果其子节点都是纯色,并且它上面的那一坨结 ...
- Codeforces Round #395 (Div. 2) C
题意 : 给出一颗树 每个点都有一个颜色 选一个点作为根节点 使它的子树各自纯色 我想到了缩点后check直径 当<=3的时候可能有解 12必定有解 3的时候需要check直径中点的组成点里是否 ...
随机推荐
- MyBatis编写映射文件实现增删改操作 附说明及代码
1.看一下我们接口 package cn.bdqn.mybatis.dao; import org.apache.ibatis.annotations.Select; import cn.bdqn.m ...
- WIN10下安装USB转串口驱动出现“文件的哈希值不在指定的目录”的解决办法
今天安装openJTAG驱动时出现“文件的哈希值不在指定的目录”,系统为WIN10专业版. 原因是驱动无数字签名,在WIN10中是不安全的驱动,所以显示哈希值不在范围内不能安装. 经查阅已经解决,发放 ...
- Scapy Fuzz实现——S7协议从建连到“正常交流“(一)
转载:安全客 酝酿了“三秒钟“,准备理清逻辑写写我学习的心得,自认为和Siemens S7协议有过一段时间浅浅的“交流”,所以这过程中涉及到了自己整理的自认为有用的东西,涉及工具.脚本这般,发出来让大 ...
- 破解WPA工具Tkiptun-ng
1.关于Tkiptun-ng 该工具能够将一些帧插入到使用WPA TKIP且开启Qos的无线网络中. 2.Tkiptun-ng原理 Tkiptun-ng设计思路主要是通过获得一个包含明文与MIC(消息 ...
- Java基础编程题——水仙花数
package com.yangzl.basic; /** * 题目:打印出所有的"水仙花数". * 所谓"水仙花数"是指一个三位数, * 其各位数字立方和等于 ...
- D - 文理分科 (网络流->最小割)
题目链接:https://cn.vjudge.net/contest/281959#problem/D 题目大意:中文题目 具体思路:我们需要求出最大的满意值,从另一方面想,我们可以求出总的满意值,然 ...
- adboost方法(转载)
转载链接:http://blog.csdn.net/google19890102/article/details/46376603 一.集成方法(Ensemble Method) 集成方法主要 ...
- git 使用https 和SSH 提交远程库小总结
一.使用https提交远程库 首先已经git commit -m “注释” 本地仓库关联远程github服务器:git remote add origin “https://XXXX.git” 提交 ...
- elasticsearch5.0.1集群一次误删除kibana索引引发的血案
elasticsearch集群中一次删除kibana索引引发的血案 1.问题发生的过程: 早上的时候有某个索引无法看到报表数据,于是就点该报表多次,估计集群被点挂了,报错:Elasticsearch ...
- centos6.5环境openldap实战之ldap配置详解及web管理工具lam(ldap-account-manager)使用详解
ldap常用名称解释 1.环境搭建 操作系统:centos6.5 x86_64 关闭防火墙.selinux 开启时间同步 # crontab -e 加入 # time sync */5 * * * * ...