layout: post
title: Codeforces Round 544(Div. 3)
author: "luowentaoaa"
catalog: true
tags:
mathjax: true
- codeforces
传送门
A.Middle of the Contest (签到)
题意
求两个时间的中间时刻
#include
using namespace std;
typedef long long ll;
const ll mod=1e8+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
int main()
{
/*std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);*/
int h1,h2,m1,m2;
string s;
cin>>s;
h1=(s[0]-'0')*10+s[1]-'0';
m1=(s[3]-'0')*10+s[4]-'0';
cin>>s;
h2=(s[0]-'0')*10+s[1]-'0';
m2=(s[3]-'0')*10+s[4]-'0';
int h3=h1*60+m1;
int m3=h2*60+m2;
int num=(h3+m3)/2;
printf("%02d:%02d\n",num/60,num%60);
return 0;
}
B - Preparation for International Women's Day (水)
题意
求有多少个数可以组合成K的倍数
#include
using namespace std;
typedef long long ll;
const ll mod=1e8+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
int low[150];
int high[150];
int flag[150];
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
int a;cin>>a;
high[a%k]++;
}
int ans=high[0]/2;
for(int i=1;i
C - Balanced Team (单调队列)
#include
using namespace std;
typedef long long ll;
const ll mod=1e8+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
int a[maxn];
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,k;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
dequedq;
sort(a+1,a+1+n);
int ans=0;
for(int i=1;i<=n;i++){
dq.push_back(a[i]);
while(!dq.empty()&&dq.front()+5
D - Zero Quantity Maximization (map)
#include
using namespace std;
typedef long long ll;
const ll mod=1e8+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
ll a[maxn],b[maxn];
map,int>mp;
int ans=0;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n;
cin>>n;
int zero=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int j=1;j<=n;j++)cin>>b[j];
for(int i=1;i<=n;i++){
if(a[i]==0&&b[i]==0){
zero++;
continue;
}
if(a[i]==0)continue;
ll q=__gcd(abs(a[i]),abs(b[i]));
a[i]/=q;
b[i]/=q;
if(a[i]<0)b[i]=-b[i],a[i]=-a[i];
mp[{a[i],b[i]}]++;
ans=max(ans,mp[{a[i],b[i]}]);
}
cout<
E - K Balanced Teams (DP)
#include
using namespace std;
typedef long long ll;
const ll mod=1e8+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
int dp[5500][5500],a[maxn],b[maxn];
dequedq;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,k,ans=0;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
dq.push_back(a[i]);
while(!dq.empty()&&dq.front()+5
F1 - Spanning Tree with Maximum Degree (MST)
#include
using namespace std;
typedef long long ll;
const ll mod=1e8+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
vectorG[maxn];
int a[maxn],b[maxn],fa[maxn],d[maxn];
int find(int x){
return x==fa[x]?fa[x]:fa[x]=find(fa[x]);
}
void fix(int u,int v){
int fu=find(u);
int fv=find(v);
if(fv==fu)return;
fa[fu]=fv;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,m,mx=0,rt;
cin>>n>>m;
for(int i=1;i<=n;i++)fa[i]=i;
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i];
d[a[i]]++;d[b[i]]++;
if(d[a[i]]>mx)mx=d[a[i]],rt=a[i];
if(d[b[i]]>mx)mx=d[b[i]],rt=b[i];
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
for(int i=0;i
F2 - Spanning Tree with One Fixed Degree (构造)
#include
using namespace std;
typedef long long ll;
const ll mod=1e8+7;
const int maxn=1e6+50;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
typedef unsigned long long ull;
vectorG[maxn];
int a[maxn],b[maxn],fa[maxn],d[maxn];
int find(int x){
return x==fa[x]?fa[x]:fa[x]=find(fa[x]);
}
void fix(int u,int v){
int fu=find(u);
int fv=find(v);
if(fv==fu)return;
fa[fu]=fv;
}
bool flag[maxn];
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)fa[i]=i;
int cnt=0;
for(int i=1;i<=m;i++){
cin>>a[i]>>b[i];
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
if(a[i]!=1&&b[i]!=1&&(find(a[i])!=find(b[i])))fix(a[i],b[i]),cnt++;
}
for(int i=1;i<=m;i++){
if(a[i]==1||b[i]==1){
int aa=find(a[i]);
int bb=find(b[i]);
if((aa!=bb)&&k){
fix(a[i],b[i]);
k--;cnt++;
flag[i]=1;
}
}
}
for(int i=1;i<=m;i++){
if(a[i]==1||b[i]==1){
int aa=find(a[i]);
int bb=find(b[i]);
if(aa==bb&&flag[i]==0&&k){
k--;
flag[i]=1;
}
}
}
if(k||cnt!=n-1)cout<<"NO"<