Practice_Codeforces Round #405 (Div. 2)

来源:互联网 发布:mac office 编辑:程序博客网 时间:2024/06/01 08:39

蒟蒻的水题之路


在A+B的道路上渐行渐远再见

即使这样,窝还是要做A+B

A. Bear and Big Brother
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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?

Input

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.

Output

Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.

Examples
input
4 7
output
2
input
4 9
output
3
input
1 1
output
1
Note

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.


题目链接:http://codeforces.com/contest/791/problem/A
题意:给定两个数a和b,然后每次:a*=3, b*=2, 问多少次后‘a’大于‘b’。
题解:简单while循环
这个水题连窝这个蒟蒻都看不下去了!出题人有点过分!

#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;}

B. Bear and Friendship Condition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 nm 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 (XYZ), 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.

Input

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.

Output

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).

Examples
input
4 31 33 41 4
output
YES
input
4 43 12 33 41 2
output
NO
input
10 44 35 108 91 2
output
YES
input
3 21 22 3
output
NO
Note

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.


题目链接:http://codeforces.com/contest/791/problem/B
(哦这个题目窝不太会!嗨呀,考了并查集,我太弱了,还没学过!)
参考(学习,也叫抄袭)来源:Angel_Kitty

分析:

给你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;}

知识点学习:
1.并查集
2.完全图,有向图,无向图


0 0