A - Candy Bags
简单数学题,输出各行总和相等。
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<vector>
using namespace std;
int a[101][101];
int main()
{
int n,i,j,m,x;
cin>>n;
x=n,
m=(1+n*n)*n/2;//题目中n一定为偶数
i=1;
while(x--)
{
for(j=1; j<=n/2; j++)
{
if(j==1)
{
cout<<i+j-1<<' '<<n*n+1-i-j+1;
}
else
{
cout<<' '<<i+j-1<<' '<<n*n+1-i-j+1;
}
}
i=i+j-1;
cout<<endl;
}
return 0;
}
B - Eight Point Sets
当时就没读懂题意,WA翻了,,,要注意题意,形成矩形!!!
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cstdio>
using namespace std;
struct xl
{
int x,y;
}s[10];
bool cmp(const xl &a,const xl &b)
{
if(a.x!=b.x)
{
return a.x<b.x;
}
return a.y<b.y;
}
int main()
{
int i,a,b,c;
bool ans=true;
for(i=0; i<8; i++)
{
scanf("%d%d",&s[i].x,&s[i].y);
}
sort(s,s+8,cmp);
if(s[0].x!=s[1].x||s[1].x!=s[2].x)
{
ans=false;
}
if(s[3].x!=s[4].x)
{
ans=false;
}
if(s[5].x!=s[6].x||s[6].x!=s[7].x)
{
ans=false;
}
a=s[0].y;
b=s[1].y;
c=s[2].y;
if(a>=b||b>=c)
{
ans=false;
}
if(s[3].y!=a||s[4].y!=c)
{
ans=false;
}
if(s[5].y!=a||s[6].y!=b||s[7].y!=c)
{
ans=false;
}
if(ans==true)
{
cout<<"respectable"<<endl;
}
else
{
cout<<"ugly"<<endl;
}
return 0 ;
}
C - Secrets
数论题,,,推出公式就行。。
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cstdio>
#include<vector>
using namespace std;
long long a[36];
int main()
{
long long n,i,sum=1;
cin>>n;
a[0]=1;
for(i=1;i<=36;++i)
{
a[i]=a[i-1]*3;
}
for(i=1;i<=36;++i)
{
if(a[i]==n)
{
cout<<1<<endl;
return 0;
}
}
if(n%3==0)
{
for(i=1;i<=36;++i)
{
if(n%a[i]!=0)
{
cout<<n/a[i]+1<<endl;
return 0;
}
}
}
else
{
cout<<n/3+1<<endl;
}
//cout<<a[36]<<endl;
return 0;
}