div2-20121208

2019年02月08日 ⁄ 综合 ⁄ 共 2379字 ⁄ 字号 评论关闭

A

int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,m,t=0;
//cin>>n>>m;
while(scanf("%d%d",&n,&m)!=EOF)
{
int ans1=min(m,n);
if(m>n)
t=1;
else
t=2;
int ans2=max(m,n);
for(int i=0;i<ans1;++i)
{
if(t==2)
printf("BG");
else
printf("GB");
}
if(t==2)
for(int i=0;i<ans2-ans1;++i)
{
//cout<<'B';
printf("B");
}
else
for(int i=0;i<ans2-ans1;++i)
{
//cout<<'G';
printf("G");
}
}
return 0;
}

B

#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n;
while(cin>>n)
{
for(int i=0;i<n;++i)
cin>>a[i];
sort(a,a+n);
int ans1=n,ans2;
for(int i=0;i<n;++i)
{
if(a[i]==a[i-1]&&i>=1)
{
continue;
}
ans2=i;
for(int j=n-1;i<j;j--)
{
if(2*a[i]>=a[j])
break;
ans2++;
}
//cout<<ans2<<endl;
ans1=min(ans1,ans2);
}
cout<<ans1<<endl;
}
return 0;
}

C

#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int a[100005];
int go(int r1,int c1,int r2,int c2)
{
int ans=0;
if(r1<r2)
{
for(int i=r1+1; i<=r2; ++i)
{
if(a[i]+1<c1)
{
c1=a[i]+1;
}
ans++;
}
ans+=abs(1.0*(c1-c2));
}
else if(r1>r2)
{
for(int i=r1-1; i>=r2; --i)
{
if(a[i]+1<c1)
{
c1=a[i]+1;
}
ans++;
}
ans+=abs(1.0*(c1-c2));
}
else
{
ans=abs(1.0*(c1-c2));
}
return ans;
}

int main()
{
int n,r1,r2,c1,c2,ans,ans1,ans2;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
while(cin>>n)
{
ans=0;
for(int i=1; i<=n; ++i) cin>>a[i];
cin>>r1>>c1>>r2>>c2;
int rr1=r1,cc1=c1;
ans1=0,ans2=1000000;
int j=0;
while(--rr1)
{
j++;
if(a[rr1]+1<cc1)
{
cc1=a[rr1]+1;
}
ans1=j+go(rr1,cc1,r2,c2);
ans2=min(ans1,ans2);
}
rr1=r1,cc1=c1,j=0;
while(rr1<=n)
{
if(a[rr1]+1<cc1)
{
cc1=a[rr1]+1;
}
ans1=j+go(rr1,cc1,r2,c2);
ans2=min(ans1,ans2);
rr1++;
j++;
//cout<<ans2<<endl;
}
ans+=ans2;
cout<<ans<<endl;
}
return 0;
}

D E

【上篇】
【下篇】