第一天的题感觉有点偏难把,队友a了一题,然后我一直在做G题,然后还是超时了,还是挺简单的,但是自己的优化没做好,超时了一倍。
这道题是说给你n个点,然后给你n-1条无向的边,再给你这n个点的权值,然后给你两个点a与b,从a到b依次走过的权值记录为T0,T1,T2......Tm,然后给你一个k值,然后让你计算从a到b经过的所有权值Tpk(pk小于m)他们的异或值,这个题理解起来并不难,不过应该是在找联通点的时候超时了,先贴上现在超时的代码,等修改后再贴改后的上来。
import java.util.Scanner;
public class Main
{
static int[][] map=new int[505][505];
static int[] x=new int[505];
static int t=0;
static int[] zb=new int[505];
public static void find(int[][] mapp,int end,int now,int tt,int[] w)
{
int j,i;
for(j=0;j<505;j++)
{
if(mapp[now][j]==1&&j==end)
{
w[tt]=x[j];
t=tt+1;
for(i=0;i<505;i++)
zb[i]=w[i];
return;
}
if(mapp[now][j]==1&&j!=end)
{
mapp[now][j]=0;
mapp[j][now]=0;
w[tt]=x[j];
find(mapp,end,j,tt+1,w);
mapp[now][j]=1;
mapp[j][now]=1;
}
}
}
public static int go(int a,int b,int k)
{
int[] ww=new int[505];
int s=0,i,j;
find(map,b,a,1,ww);
s=x[a];
for(i=1;i*k<=t;i++)
s=s^zb[i*k];
return s;
}
public static void main(String[] args)
{
int n,q,i,j,a,b,k,s;
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
n=cin.nextInt();
q=cin.nextInt();
for(i=0;i<n-1;i++)
{
a=cin.nextInt();
b=cin.nextInt();
map[a][b]=1;
map[b][a]=1;
}
for(i=1;i<=n;i++)
x[i]=cin.nextInt();
for(i=0;i<q;i++)
{
a=cin.nextInt();
b=cin.nextInt();
k=cin.nextInt();
s=go(a,b,k);
System.out.println(s);
}
}
}
}
第二天一个队友有事没来,我和cwh一人a了一道吧,最后一直再做1010,不过一直超时,其实刚开始有种想法,感觉不会超时,然而写了半天,越写越乱,然后干脆暴力,然后果不其然超时,然后有返回来用刚开始的方法然后越写越乱,只能回来再改下了,
这道题
题意:两个人A和B,然后A的年龄大,B的年龄小,然后给你这两个人的生肖,然后问你两个人的年龄最小差多少。
这题随便写就可以,就几种情况用if就可以写出来,然而因为strcmp的头文件问题编译错误了两次是最气的,哎,
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
char x[12][10]={"rat","ox","tiger","rabbit","dragon","snake","horse","sheep","monkey","rooster","dog","pig"};
char a[10],b[10];
int i,s1,s2,t;
cin>>t;
while(t--)
{
cin>>a>>b;
if(strcmp(a,b)==0)
{
cout<<12<<endl;
continue;
}
for(i=0;i<12;i++)
{
if(strcmp(a,x[i])==0)
s1=i;
if(strcmp(b,x[i])==0)
s2=i;
}
if(s1<s2)
cout<<(s1-s2)*-1<<endl;
else
cout<<12-s1+s2<<endl;
}
return 0;
}
这道题按队友说是给你一个素数,然后如果这个素数能够成为两个数的平方差,就YES否则NO,后来是公式吧Y=3X*X+3X+1。
题意:给你三个圆上的点,然后再给你一个点,问你这个点是否再圆内,这题看着听简单吧,一步步计算出圆心的坐标,然后计算下距离就行了,因为提交后hdu的服务器有点炸了,提交了也看不到自己有没有过,也没法查找了,就没再看,然后赛后看了下wa了,然后因为是两个队共用一个账号,另一个队的过了,用的高精度,我写的那个应该是精度不够,计算后精度不够了,然后wa了,还是太大意了。
Code Render Status : Rendered By HDOJ Java Code Render Version 0.01 Beta
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
double a,b,c,d,e,f,A,B,C,D,b1,b2,k1,k2,x,y,r,R,xx,yy;
int t;
t=cin.nextInt();
while(t--!=0)
{
a=cin.nextDouble();
b=cin.nextDouble();
c=cin.nextDouble();
d=cin.nextDouble();
e=cin.nextDouble();
f=cin.nextDouble();
A=(a+c)/2.0;B=(b+d)/2.0;C=(c+e)/2.0;D=(d+f)/2.0;
k1=-1.0*(c-a)/(d-b);k2=-1.0*(e-c)/(f-d);
b1=B-k1*A;b2=D-k2*C;
x=(b2-b1)/(k1-k2);
y=k1*x+b1;
R=(a-x)*(a-x)+(b-y)*(b-y);
xx=cin.nextDouble();yy=cin.nextDouble();
r=(xx-x)*(xx-x)+(yy-y)*(yy-y);
if(r<=R)
System.out.println("Rejected");
else
System.out.println("Accepted");
}
}
Brute Force Sorting
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
1. A[i] is the first element of the array, or it is no smaller than the left one A[i−1] .
2. A[i] is the last element of the array, or it is no bigger than the right one A[i+1] .
In [1,4,5,2,3] , for instance, the element 5 and the element 2 would be destoryed by Beerus. The array would become [1,4,3] . If the new array were still unsorted, Beerus would do it again.
Help Beerus predict the final array.
For each test case, the first line provides the size of the inital array which would be positive and no bigger than 100000 .
The second line describes the array with N positive integers A[1],A[2],⋯,A[N] where each integer A[i] satisfies 1≤A[i]≤100000 .
The first line contains an integer M which is the size of the final array.
The second line contains M integers describing the final array.
If the final array is empty, M should be 0 and the second line should be an empty line.
5 5 1 2 3 4 5 5 5 4 3 2 1 5 1 2 3 2 1 5 1 3 5 4 2 5 2 4 1 3 5
5 1 2 3 4 5 0 2 1 2 2 1 3 3 2 3 5
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
#include<iostream>
#include<string.h>
#include<cstring>
#include<stdio.h>
using namespace std;
int x[100005];
int y[100005];
int s,n;
void go()
{
int ss=s,a,b,i,j,flag;
for(i=1;i<=n;i++)
{
flag=0;
if(y[i]==-1)
continue;
for(j=i-1;;j--)
if(y[j]!=-1)
break;
a=j;
for(j=i+1;;j++)
if(y[j]!=-1)
break;
b=j;
if(x[i]<x[a])
{
y[i]=1;
ss--;
flag=1;
}
if(x[i]>x[b])
{
y[i]=1;
if(flag==0)
ss--;
}
}
for(i=1;i<=n;i++)
if(y[i]==1)
y[i]=-1;
if(ss==s)
return;
else
{
s=ss;
go();
}
}
int main()
{
int t,i,j;
cin>>t;
while(t--)
{
cin>>n;
x[0]=0;
x[n+1]=999999;
for(i=0;i<=n+1;i++)
y[i]=0;
for(i=1;i<=n;i++)
scanf("%d",&x[i]);
s=n;
go();
cout<<s<<endl;
for(i=1;i<=n;i++)
if(y[i]!=-1)
cout<<x[i]<<" ";
cout<<endl;
}
return 0;
}