Codeforces Round #744 (Div. 3)【A-D E的题解】
目錄
- A. Elections【800 / 模擬】
- B. Make it Divisible by 25【900 / 思維】
- C. Save More Mice【1000 / 貪心】
- D1. All are Same【1100 / 數(shù)學(xué) 最大公約數(shù)】
- E. Gardener and Tree【1600 / 拓?fù)洹?/li>
A. Elections【800 / 模擬】
https://codeforces.com/contest/1593/problem/A
B. Make it Divisible by 25【900 / 思維】
https://codeforces.com/contest/1593/problem/B
打表找規(guī)律,你會(huì)發(fā)現(xiàn)只要是'00' ,'25', '75, '50'這四種情況為后綴的必為25的倍數(shù)。
故需要枚舉這4種情況,貪心的刪除求解,總的求一個(gè)min。
C. Save More Mice【1000 / 貪心】
https://codeforces.com/contest/1593/problem/C
排序,從后到前的判斷,可不可以,然后累加距離和。
D1. All are Same【1100 / 數(shù)學(xué) 最大公約數(shù)】
https://codeforces.com/contest/1593/problem/D1
求其除了最小數(shù)外其它數(shù)的公共最大公約數(shù)
E. Gardener and Tree【1600 / 拓?fù)洹?/h1>
https://codeforces.com/contest/1593/problem/E
拓?fù)涓阋幌?/p>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5*5;
int t,n,k;
int d[N]={0};
vector<int>ve[N];
int main(void)
{cin>>t;while(t--){cin>>n>>k;for(int i=1;i<=n;i++) ve[i].clear();memset(d,0,sizeof 4*(n+1));for(int i=1;i<=n-1;i++){int a,b; cin>>a>>b;ve[a].push_back(b);ve[b].push_back(a);d[a]++,d[b]++;}queue<int>q;for(int i=1;i<=n;i++) if(d[i]<=1) q.push(i);//<=1 的目的是 有孤點(diǎn)int cnt=n;while(q.size()&&k){queue<int>temp;cnt-=q.size();while(q.size()){auto t=q.front(); q.pop();for(int i=0;i<ve[t].size();i++){if(--d[ve[t][i]]==1) temp.push(ve[t][i]);}}q=temp;k--;}cout<<cnt<<endl;}return 0;
}
總結(jié)
以上是生活随笔為你收集整理的Codeforces Round #744 (Div. 3)【A-D E的题解】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1059 Prime Factors (
- 下一篇: 1060 Are They Equal