今天比较悲催,好不容易等到现场版,结果一个题~
a题(水):
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char map[5][5];
int main()
{
while(scanf("%s",&map[0])!=EOF)
{
for(int i=1;i<4;i++)
scanf("%s",map[i]);
int flag=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
int cou=0;
if(map[i][j]=='#')
cou++;
if(map[i][j+1]=='#')
cou++;
if(map[i+1][j+1]=='#')
cou++;
if(map[i+1][j]=='#')
cou++;
if(cou>=3)
{
flag=1;
break;
}
cou=0;
if(map[i][j]=='.')
cou++;
if(map[i][j+1]=='.')
cou++;
if(map[i+1][j+1]=='.')
cou++;
if(map[i+1][j]=='.')
cou++;
if(cou>=3)
{
flag=1;
break;
}
}
if(flag)
break;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
b题:
二分查询。
#include<stdio.h>
#include<stdlib.h>
int main()
{
long long n,k,i;
scanf("%I64d%I64d",&n,&k);
n=n-1;
k=k-1;
if(n==0)
printf("0\n");
else if(((k+1)*k)/2<n)
printf("-1");
else
if(n<=k)
printf("1");
else
{
long long r=k,l=1;
long long mid=(r+l)/2;
while(!((i=((mid+k)*(k-mid+1)/2))<=n&&n-i<mid))
{
if(i<n)
{
r=mid;
mid=(l+r)/2;
}
else
{
l=mid+1;
mid=(r+l)/2;
}
}
if((((mid+k)*(k-mid+1)/2)==n))
printf("%I64d",k-mid+1);
else
printf("%I64d",k-mid+2);
}
}
c题:
比较坑吧,判断好-1的情况后,根据规律计算即可。
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1e5+10;
int n,a[maxn];
bool vis[maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n%4!=0&&n%4!=1)
{
printf("-1\n");
continue;
}
else
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n/2;i+=2)
{
a[i]=n-i;
a[n-i]=n-i+1;
a[n-i+1]=i+1;
a[i+1]=i;
}
if(n&1)
a[n/2+1]=n/2+1;
for(int i=1;i<=n;i++)
printf("%d ",a[i]);
}
}
return 0;
}