Practice_Codeforces Round #405 (Div. 2)
来源:互联网 发布:mac office 编辑:程序博客网 时间:2024/06/01 08:39
蒟蒻的水题之路
在A+B的道路上渐行渐远
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
4 7
2
4 9
3
1 1
1
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
#include <iostream>using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); int a, b; cin >> a >> b; int sum = 0; while(a <= b) { a *= 3; b *= 2; sum++; } cout << sum << endl; return 0;}
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures).
There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves.
Let A-B denote that members A and B are friends. Limak thinks that a network is reasonable if and only if the following condition is satisfied: For every three distinct members (X, Y, Z), if X-Y and Y-Z then also X-Z.
For example: if Alan and Bob are friends, and Bob and Ciri are friends, then Alan and Ciri should be friends as well.
Can you help Limak and check if the network is reasonable? Print "YES" or "NO" accordingly, without the quotes.
The first line of the input contain two integers n and m (3 ≤ n ≤ 150 000, ) — the number of members and the number of pairs of members that are friends.
The i-th of the next m lines contains two distinct integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi). Members ai and bi are friends with each other. No pair of members will appear more than once in the input.
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
4 31 33 41 4
YES
4 43 12 33 41 2
NO
10 44 35 108 91 2
YES
3 21 22 3
NO
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
分析:
给你m对朋友关系; 如果x-y是朋友,y-z是朋友,要求x-z也是朋友. 问你所给的图是否符合!
用DFS去找他们之间的关系,有向图去算m个点对应的边的数量,看是否相等!
#include<bits/stdc++.h>typedef long long ll;using namespace std;const int N=150000+100;int a[N];int b[N];int vis[N];vector<int>vc[N];//定义一个向量ll t;void DFS(int x){ t++;//计算有关的节点没有被标记过 vis[x]=1; for(int j=0;j<vc[x].size();j++) { if(vis[vc[x][j]]==0)//如果和它相连的点没有被标记, DFS(vc[x][j]); }}int main(){ int m,n; int x,y; scanf("%d%d",&n,&m); memset(vis,0,sizeof(vis)); memset(b,0,sizeof(b)); for(int i=0;i<m;i++) { scanf("%d%d",&x,&y); vc[x].push_back(y);//找到x和y的关系 vc[y].push_back(x); b[x]=1; b[y]=1; } ll sum=0; for(int i=1;i<=n;i++) { if(vis[i]==0&&b[i]) { t=0; DFS(i); sum=sum+t*(t-1);//(t-1)*t求边数,完全图 } } if(2*m!=sum)cout<<"NO"<<endl;//N个完全图的边数等于m个节点所构成的边数 else cout<<"YES"<<endl;}
- Practice_Codeforces Round #405 (Div. 2)
- Practice_Codeforces Round #410 (Div. 2)
- Practice_Codeforces Round #409 (Div. 2)
- Practice_Codeforces Round #408 (Div. 2)
- Practice_Codeforces Round #407 (Div. 2)
- Practice_Codeforces Round #406 (Div. 2)
- Practice_Codeforces Round #404 (Div. 2)
- Practice_Codeforces Round #411 (Div. 2)
- Practice_Codeforces Round #412 (Div. 2)
- Practice_Codeforces Round #413 (Div. 2)
- Codeforces Round #405 (Div. 2)
- Round #146(Div 2)
- Round #145(Div 2)
- Round #338 (Div. 2)
- Round #292 (Div. 2)
- Codeforces Round #346 (Div. 2)Round House
- Codeforces Round #346 (Div. 2)Round House
- Codeforces Round #167 (Div. 2 && Div.1)
- INPUT子系统
- Android6.0 otg插入U盘 流程
- JS正则表达式
- bzoj 4245: [ONTAK2015]OR-XOR
- 在南通选择JAVA培训机构的独门秘诀
- Practice_Codeforces Round #405 (Div. 2)
- nyoj123 士兵杀敌(四) 树状数组之插线问点
- 算数基本定理——素因数分解序列生成
- 关于android通过servlet访问MySql数据库的问题(附带简单的JSON使用)
- 表的某个字段按,隔开使用sql拆成相应的行
- 哪些因素影响ABBYY FineReader 12的识别质量
- ubuntu下 sublime-text 支持中文输入
- JUnit单元测试
- C语言数据结构-桟——括号的匹配检验