Codeforces Round 871 Div. 4

D
赛时感觉递归会超时,实际上根据主定理算一下并不会。

#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int,int>
   
using namespace std;
using ll = long long;
 
int n,m;
 
bool f(int n)
{
    if(n==m) return true;
    if(n==0||n%3!=0) return false;
    else 
    {
        return f(n/3*2)|f(n/3);
    }
}
 
void solve()
{
    cin>>n>>m;
    if(n==m) {cout<<"YES"<<endl; return ;}
    if(n%3||m>n) {cout<<"NO"<<endl; return ;}
    if(f(n)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
 
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T; cin>>T;
    while(T--)
    solve();
    return 0;
}

F
根据题意可以看出,所有节点的出度最多有三种情况,最多的那种显然是最外层的点,如果有三种出度情况, y y y 就是最多的那种情况除以第二多的,即中间那层的节点数量,如果只有两种,说明最里面的和中间的节点出度恰好相同,只需要对第二多的数量减一即可。

#include<bits/stdc++.h>
#define endl '\n'
#define pii pair<int,int>
   
using namespace std;
using ll = long long;

const int maxn = 203;
int a[maxn];
map<int,int> mp;

bool cmp(int x,int y)
{
    return x>y;
}

void solve()
{
    mp.clear();
    memset(a,0,sizeof(a));
    int n,m;
    cin>>n>>m;
    int u,v;
    for(int i=1;i<=m;i++)
    {   
        cin>>u>>v;
        a[u]++,a[v]++;
    }
    for(int i=1;i<=n;i++) // 有 a[i] 条边的点有 mp[a[i]] 个
    if(a[i]) mp[a[i]]++;
    vector<int> cnt;
    for(auto x:mp)
    {
        cnt.push_back(x.second);
    }
    sort(cnt.begin(),cnt.end());

    if (cnt.size() == 3) {
		cout << cnt[1] << ' ' << cnt[2] / cnt[1] << endl;
	}
	else {
		cout << cnt[0] - 1 << ' ' << cnt[1] / (cnt[0] - 1) << endl;
	}
    

}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T; cin>>T;
    while(T--)
    solve();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值