http://codeforces.com/contest/1088
昨晚打了cf div.2.。。手残,,,一共wa了三发,,,简直了,,,也不知道最近这是怎么了,总是交WA,怕是脑子也不太好用了。。。
而且昨晚真的,,cf的提交页面刷不出来,,卡了近5min,导致10min才交了A题,。,然后B题智障,WA了三次。。C题+=写成了=,,,,也是智障错误,,,导致凉凉,,,
-------------------------------------------------------------------------------------------------
A. Ehab and another construction problem
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int x,ok;
int main()
{
cin>>x;
for(int i=1;i<=x;i++)
{
for(int j=1;j<=x;j++)
{
if(i%j==0&&i*j>x&&i/j<x)
{
cout<<i<<" "<<j<<endl;
return 0;
}
}
}
cout<<"-1"<<endl;
return 0;
/*
if(ok)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
*/
}
我是做复杂了,其实仔细想想,直接去重,然后排个序,挨个输出与前一个的差值就可以了。。我昨晚可能也是有点着急,没有细想就直接暴力模拟了,,,导致WA+2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,ok,a[100005],s,n,k;
int main()
{
map<long long,int>ma;
cin>>n>>k;
s=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&x);
if(x!=0&&ma[x]==0)
{
a[++s]=x;
ma[x]=1;
//cout<<s<<endl;
}
}
sort(a+1,a+1+s);
int i=1;
x=0;
while(k--)
{
if(i>s) {cout<<"0"<<endl;continue;}
cout<<a[i]-x<<endl;
x+=a[i]-x;
i++;
}
return 0;
/*
if(ok)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
*/
}
/*
*/
C. Ehab and a 2-operation task
题意给提示了,n+1次,但是我做的时候也是着急了,,因为B题wa了两次,然后就x+=ans,写成了x=ans..
n+1永远成立,逆序,依次,1操作,将第i个数变成(n+1)的某倍数+i,第i+1步全部取余(n+1)就可以了。。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,ok,a[10005],s,n,ans;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
x=0;
cout<<n+1<<endl;
for(int i=n;i>=1;i--)
{
s=a[i];
s+=x;
if((s%(n+1))-i<=0)
{
ans=i-(s%(n+1));
x+=ans;
}
else
{
ans=n-(s%(n+1))+i+1;
x+=ans;
}
cout<<"1 "<<i<<" "<<ans<<endl;
}
cout<<"2 "<<n<<" "<<n+1<<endl;
return 0;
/*
if(ok)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
*/
}
/*
*/
D题交互题,讨厌,,,过。。
终于补了/。。https://blog.csdn.net/qq_37868325/article/details/103828769
E. Ehab and a component choosing problem
选若干个联通块,最大化联通块点权和与联通块个数的比值。
那就先求出最大的联通块大小,然后贪心选就好了。。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Maxn=610000;
int to[Maxn],nxt[Maxn],first[Maxn],tot=1;
int ans,a[Maxn],n,u,v;
ll sxz=0x8000000000000000;
inline void add(int u,int v) {
to[tot]=v;
nxt[tot]=first[u];
first[u]=tot++;
to[tot]=u;
nxt[tot]=first[v];
first[v]=tot++;
}
ll dp1(int root,int fa) {
ll zhy=a[root];
for(int i=first[root];i;i=nxt[i])
if(to[i]!=fa) zhy+=max(dp1(to[i],root),0ll);
sxz=max(sxz,zhy);
return zhy;
}
ll dp2(int root,int fa) {
ll zhy=a[root];
for(int i=first[root];i;i=nxt[i])
if(to[i]!=fa) zhy+=max(dp2(to[i],root),0ll);
if(zhy==sxz) {
ans++;
return 0;
}
return zhy;
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<n;i++) {
scanf("%d%d",&u,&v);
add(u,v);
}
dp1(1,1);
dp2(1,1);
printf("%I64d %d\n",sxz*ans,ans);
return 0;
}