Codeforces Round #318(Div 1) 573A, 573B,573C
2015-08-30 15:00
381 查看
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
这场的前两题完全是手速题。。。A题写了7分钟,交的时候已经500+了,好在B题出的速度勉强凑活吧,and C题也没有FST
A. Bear and Poker
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input
First line of input contains an integer n (2 ≤ n ≤ 105), the number of players.
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — the bids of players.
Output
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Sample test(s)
input
output
input
output
Note
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal.
A题没啥好说的,把因为可以乘2或乘三,那只要看看除了2和3之外,其他的因子是否相同即可
代码君
C. Bear and Drawing
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that tree is a connected graph consisting of n vertices and n - 1 edges.
Limak chose a tree with n vertices. He has infinite strip of paper with two parallel rows of dots. Little bear wants to assign vertices of a tree to some n distinct dots on a paper so that edges would intersect only at their endpoints — drawn tree must be planar. Below you can see one of correct drawings for the first sample test.
统计有多少个一定要占一半边的子树,如果超过两个,那就是不符合的。[/b]
树形dp,第一次dfs统计好所有子树,第二遍,把根的信息传下来一起考虑就ok了。
这场的前两题完全是手速题。。。A题写了7分钟,交的时候已经500+了,好在B题出的速度勉强凑活吧,and C题也没有FST
A. Bear and Poker
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.
Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot?
Input
First line of input contains an integer n (2 ≤ n ≤ 105), the number of players.
The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — the bids of players.
Output
Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise.
Sample test(s)
input
4 75 150 75 50
output
Yes
input
3 100 150 250
output
No
Note
In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid.
It can be shown that in the second sample test there is no way to make all bids equal.
A题没啥好说的,把因为可以乘2或乘三,那只要看看除了2和3之外,其他的因子是否相同即可
//##################### //Author:fraud //Blog: http://www.cnblogs.com/fraud/ //##################### //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <sstream> #include <ios> #include <iomanip> #include <functional> #include <algorithm> #include <vector> #include <string> #include <list> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <climits> #include <cctype> using namespace std; #define XINF INT_MAX #define INF 0x3FFFFFFF #define mp(X,Y) make_pair(X,Y) #define pb(X) push_back(X) #define rep(X,N) for(int X=0;X<N;X++) #define rep2(X,L,R) for(int X=L;X<=R;X++) #define dep(X,R,L) for(int X=R;X>=L;X--) #define clr(A,X) memset(A,X,sizeof(A)) #define IT iterator typedef long long ll; typedef pair<int,int> PII; typedef vector<PII> VII; typedef vector<int> VI; int h[100010]; int dp[100010]; int dp2[100010]; int main() { ios::sync_with_stdio(false); int n; cin>>n; rep(i,n)cin>>h[i]; int maxx = 0; dp[0] = dp2[n-1] = 1; rep2(i,1,n-1)dp[i] = min(h[i],dp[i-1]+1); dep(i,n-2,0)dp2[i] = min(h[i],dp2[i+1]+1); rep(i,n)dp[i] = min(dp[i],dp2[i]); rep(i,n)maxx = max(dp[i],maxx); cout<<maxx<<endl; return 0; }
代码君
C. Bear and Drawing
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that tree is a connected graph consisting of n vertices and n - 1 edges.
Limak chose a tree with n vertices. He has infinite strip of paper with two parallel rows of dots. Little bear wants to assign vertices of a tree to some n distinct dots on a paper so that edges would intersect only at their endpoints — drawn tree must be planar. Below you can see one of correct drawings for the first sample test.
统计有多少个一定要占一半边的子树,如果超过两个,那就是不符合的。[/b]
树形dp,第一次dfs统计好所有子树,第二遍,把根的信息传下来一起考虑就ok了。
//##################### //Author:fraud //Blog: http://www.cnblogs.com/fraud/ //##################### //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <sstream> #include <ios> #include <iomanip> #include <functional> #include <algorithm> #include <vector> #include <string> #include <list> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <climits> #include <cctype> using namespace std; #define XINF INT_MAX #define INF 0x3FFFFFFF #define mp(X,Y) make_pair(X,Y) #define pb(X) push_back(X) #define rep(X,N) for(int X=0;X<N;X++) #define rep2(X,L,R) for(int X=L;X<=R;X++) #define dep(X,R,L) for(int X=R;X>=L;X--) #define clr(A,X) memset(A,X,sizeof(A)) #define IT iterator typedef long long ll; typedef pair<int,int> PII; typedef vector<PII> VII; typedef vector<int> VI; vector<int>G[100010]; int dp[100010]; int ff = 0; void dfs(int u,int fa){ int num = 0; int sz = G[u].size(); rep(i,sz){ int v = G[u][i]; if(v == fa)continue; dfs(v,u); dp[u] += dp[v]; num++; } if(!dp[u])dp[u] = 1; if(dp[u] == 2 && num == 1)dp[u]++; } void dfs2(int u,int fa,int num){ int sz = G[u].size(); int n = 0; if(num>2)n++; rep(i,sz){ int v = G[u][i]; if(v == fa)continue; int tmp = 1; tmp = max(num+dp[u]-dp[v],tmp); if(tmp == 2 && num == 2)tmp = 3; dfs2(v,u,tmp); if(dp[v]>2)n++; } if(n>2)ff = 1; } int main() { ios::sync_with_stdio(false); int n; cin>>n; int u,v; rep(i,n-1){ cin>>u>>v; u--;v--; G[u].pb(v); G[v].pb(u); } dfs(0,-1); dfs2(0,-1,0); if(ff)cout<<"No"<<endl; else cout<<"Yes"<<endl; return 0; }
相关文章推荐
- OSPF链路MD5认证
- 重载函数
- python 内置函数
- Hadoop2.6.0安装详解(亲测有效)
- UVa 1609:Foul Play(递归+构造)
- MongoDB (十) MongoDB Limit/限制记录
- C#生成时间戳
- [LeetCode] Permutations
- 使用 VisualVM 进行性能分析及调优
- leetcode 231: Power of Two
- PCIE协议解析 synopsys IP MSI Capability 读书笔记(11)
- Android应用程序用户界面(六)
- Senior's Gun-------(BestCoder Round #47)
- hdu 5423 Rikka with Tree
- C# NotifyIcon实现单击左键也弹出菜单的方法
- C++ 线程池的简易实现
- 剑指offer-第六章面试中的各项能力(和为S的两个数字VS和为S的连续正序列)
- maven的profile
- HDU 3397 Sequence operation(线段树区间合并)
- multiprocessing在python中的高级应用-进程池