您的位置:首页 > 其它

湖南四校联合训练赛 2013 Warm Up 14

2013-10-27 20:08 204 查看
链接:  http://acm.hnu.cn/online/?action=problem&type=list&courseid=261

这次题目确实很水。。数据也不强。

A :

 A * A   = C*C - B*B  =  (C+B) *(C-B)     

设 x=C+B  , y=C-B,      则C = (X+Y)/2   ,   B= (X-Y)/2,     而x  和  y 均为 A*A 的因子。。只需扫一遍,累加合法解即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
typedef long long LL;
using namespace std;

int main()
{
LL A,B,C;
while(cin>>A){
LL x,y;
int ans=0;
for(x=1;x<=A;x++){
if((A*A)%x) continue;
y=(A*A)/x;
if((x+y)%2) continue;
if((y-x)%2) continue;
B = (y-x) /2;
C = (x+y) /2;
if(B<=A || C<=A) continue;
if(A*A + B*B == C*C) ans++;
}
printf("%d\n",ans);
}
return 0;
}


B  : 

#include <iostream>
#include <cstdio>
using namespace std;

int F(int x){
if(x<10) return x;
int ans=1;
while(x){
ans *= x%10;
x/=10;
}
return ans;
}

int main()
{
int S;
while(scanf("%d",&S)!=EOF && S){
printf("%d",S);
while(S>=10){
S=F(S);
printf(" %d",S);
}
printf("\n");
}
return 0;
}


C :   阳神的代码。

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string.h>
#include<queue>
#include<stack>
#define eps 1e-6
#define MAXN 105
using namespace std;
const double pi=acos(-1.0);
struct LINE
{
double x1,y1,x2,y2;
}L[MAXN];
int P[MAXN][2];
double Mul(double X1,double Y1,double X2,double Y2,double X3,double Y3)
{
double x1,y1,x2,y2;
x1=X2-X1,y1=Y2-Y1;
x2=X3-X1,y2=Y3-Y1;
return x1*y2-x2*y1;
}
bool corss(int p1,int p2)
{
double q1,q2;
q1=Mul(L[p1].x1,L[p1].y1,L[p1].x2,L[p1].y2,L[p2].x1,L[p2].y1);
q2=Mul(L[p1].x1,L[p1].y1,L[p1].x2,L[p1].y2,L[p2].x2,L[p2].y2);
if (q1*q2<-eps) return true;
return false;
}
bool ok(int p1,int p2)
{
if (corss(p1,p2) && corss(p2,p1)) return false;
return true;
}
int judge(int n)
{
int i,j,f;
double qx,qy,x,y,len;
qx=qy=0,f=90;
for (i=1;i<=n;i++)
{
f+=P[i][0],len=P[i][1];
x=qx-len*sin((f-90)*pi/180);
y=qy+len*cos((f-90)*pi/180);
L[i].x1=qx,L[i].y1=qy;
L[i].x2=x, L[i].y2=y;
for (j=1;j<i;j++)
if (!ok(i,j)) return i;
qx=x,qy=y;
}
return 0;
}
int main()
{
int n,i;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
while (~scanf("%d",&n) && n)
{
for (i=1;i<=n;i++) scanf("%d%d",&P[i][0],&P[i][1]);
i=judge(n);
if (i) printf("%d\n",i);
else puts("SAFE");
}
return 0;
}


D:

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char tmp[1000];
int main()
{

freopen("input.txt","r",stdin);
while(gets(tmp)){
if(strcmp(tmp,"END")==0 ) break;

string a="",b="";
int len=strlen(tmp),p=1;
int num=0;
for(int i=0;i<len;i++){
if(tmp[i] == '\"') num++;
}
if(num!=2)  { cout<<"not a quine"<<endl; continue; }

if(tmp[0] != '\"') { cout<<"not a quine"<<endl; continue; }
while(p<len && tmp[p] != '\"' ) {
a+=tmp[p]; p++;
}
if(tmp[p+1] != ' ') { cout<<"not a quine"<<endl; continue;  }
p=p+2;
while(p<len) { b+= tmp[p] ; p++; }
if(a==b && a.size()>0 ) {
cout<<"Quine("<<a<<")"<<endl;
}
else cout<<"not a quine"<<endl;

//cout<<"("<<a<<")"<<"  **   ("<<b<<")"<<endl<<endl;
}
return 0;
}


F: 这题也是阳神敲的。

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
char s[50];
int main()
{
int cases=0,n,i,len;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
char c;
while (~scanf("%d",&n) && n)
{
printf("Simulation %d\n",++cases);
memset(s,0,sizeof(s));
c=getchar(),len=0;
while (c!='\n')
{
c=getchar();
while (c!='!')
{
if (c=='\n') goto A;
for (i=0;i<len;i++)
if (s[i]==c) break;
if (i<len)
{
s[len++]=c;
for (;i<len;i++) s[i]=s[i+1];
len--;
}else s[len++]=c;
if (len>n)
{
for (i=0;i<n;i++) s[i]=s[i+1];
len=n,s[len]='\0';
}
c=getchar();
}
puts(s);
}
A: ;
}
return 0;
}


G:     (这题过爷敲的代码)

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int main()
{
char b[25];
int t[25];
int h[10];
int p;
char a;
while (cin>>p&&p)
{
int flag=1;
memset (b,0,sizeof b);
a='A';
for (int i=0;i<p;i++)
cin>>h[i];
for (int i=0;i<20;i++)
{
t[i+1]=h[i%p];
}
for (int i=1;i<=20;i++)
{
if (b[i]!=0)
continue ;
int j=i;
while (j<=20)
{
if (b[j]!=0)
{
flag=0;
break ;
}
b[j]=a;
j+=t[j];
}
if (flag==0)
break ;
a++;
}
if (flag)
{
for (int i=1;i<=20;i++)
cout<<b[i];
cout<<endl;
}
else
cout<<"CRASH"<<endl;
}
return 0;
}


H :  爆搜即可     有很多剪枝

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int mp[10][10],path[100];
int best[100],bn;

int R,C,N;
bool vis[10][10];

int dx[2][6]={{-1,-1,0,1,1,0} , {-1,-1,0,1,1,0} };
int dy[2][6]={{-1,0,1,0,-1,-1}, {0,1,1,1,0,-1} };
bool InMap(int x,int y){
if(x<1 || x>R) return false;
if(x&1){
if(y<1 || y>C) return false;
}
else {
if(y<1 || y>C+1) return false;
}
return true;
}
int DFS(int cur,int x,int y,bool bottom){  // cout<<cur<<"  "<<x<<"  "<<y<<endl;
path[cur] = mp[x][y];
if(x==1 && cur%N==0 && cur>N && bottom) return cur;
int TY=x%2==0 ? 0 : 1;
if(x<R){
for(int t=0;t<6;t++){
int nx=x + dx[TY][t] , ny=y + dy[TY][t];
if(!InMap(nx,ny) || vis[nx][ny]) continue;
path[cur+1] = mp[nx][ny];
if(cur+1>N){
int m=(cur+1)%N==0 ? N : (cur+1)%N;
if(path[cur+1] != path[m]) continue;
}

vis[nx][ny] = true;
int tmp = DFS(cur+1,nx,ny,bottom || x==R);
if(tmp>0) return tmp;
vis[nx][ny] = false;
}
}
else if(x==R){
for(int t=2;t>=0;t--){
int nx=x + dx[TY][t] , ny=y + dy[TY][t];
if(!InMap(nx,ny) ) continue;
if(vis[nx][ny]) break;

path[cur+1] = mp[nx][ny];
if(cur+1>N){
int m=(cur+1)%N==0 ? N : (cur+1)%N;
if(path[cur+1] != path[m]) continue;
}
vis[nx][ny] = true;
int tmp = DFS(cur+1,nx,ny,bottom || x==R);
if(tmp>0) return tmp;
vis[nx][ny] = false;
}
}

return 0;
}

int main()
{
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
while(scanf("%d",&R) != EOF && R){
scanf("%d%d",&C,&N);
char ss[3];
for(int i=1;i<=R;i++){
int t=i%2 ? C : C+1;
for(int j=1;j<=t;j++){
scanf("%s",ss);
mp[i][j] = ss[0]-'A';
}
}

bn=101;
for(int i=1;i<=C;i++){
memset(vis,false,sizeof(vis));
vis[1][i] = true;
int tmp = DFS(1,1,i,false);
vis[1][i] = false;
if(tmp<=0) continue;
if(tmp<bn && tmp%N==0){
bn=tmp;
memcpy(best,path,sizeof(path));
}
if(bn/N==2 && bn!=101) break;
}
if(bn>=101) printf("no solution\n");
else {
for(int i=1;i<=bn;i++)
printf("%c",'A'+best[i]);
printf("\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: