您的位置:首页 > 其它

第三周周末总结

2017-09-17 21:51 232 查看
  第一天的题感觉有点偏难把,队友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]=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

[b]Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

Total Submission(s): 0    Accepted Submission(s): 0


[align=left]Problem Description[/align]
Beerus needs to sort an array of
N
integers. Algorithms are not Beerus's strength. Destruction is what he excels. He can destroy all unsorted numbers in the array simultaneously. A numberA[i]
of the array is sorted if it satisfies the following requirements.

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.
 

[align=left]Input[/align]
The first line of input contains an integer
T (1≤T≤10)
which is the total number of test cases.

For each test case, the first line provides the size of the inital array which would be positive and no bigger than100000.

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.
 

[align=left]Output[/align]
For eact test case output two lines.

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.
 

[align=left]Sample Input[/align]

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

 
[align=left]Sample Output[/align]

5
1 2 3 4 5
0

2
1 2
2
1 3
3
2 3 5

其实刚开始一直在做这道题,然后感觉自己刚开始的做法是可以做出来的,不过用暴力写了一遍后超时,然后有转回原来的做法有点心急了,心乱了没写完。
题意:给你一串整数,然后如果这个数在首位,那要大于等于右边第一个数,在末尾,要大于等于左边第一个数,其他情况要大于等于左边相邻的数,小于等于右边的数,每查找一次就将不符合的数拿走,最终输出还剩多少个数以及将这些数输出。
刚开始读懂题意后感觉这题还挺简单的,当时看这道题的时候挺早的吧,不过后来先去做了1008又回来做的1010,当是通过率还是40+%,然后回来就成十几了,哎,果然能率先a题的都是大佬。先是暴力然后超时了一倍多的时间,写完博客再去按照刚开始的思路来做一下试试,刚开始的思路就是定义结构体,然后定义a连接上一个数的下标,b连接的下一个数下标,第一个数为a【0】,让他等于0,保证它始终是首元素,再让a【n+1】=999999,让它始终等于尾元素,然后每次从首元素查找它要连接的下一个元素,找到就吧它的b指向这个元素,然后再重复这个动作,不过这次是让该元素的b指向要查找的下一个符合条件的元素,重复操作,然后最后设置个变量,操作后该变量不减少就查找完了,输出,思路大概是这样,等改完再传上,

下面是超时的暴力代码:
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;
}


最后总结下这几周的学习吧,这几周确实是课太多了,然后作业也挺多,不过这些却成了自己找理由懒惰的接口,老师说的很对,既然要做ACM就要付出,给自己找借口就不要做ACM了,这几星期都在为自己找理由来偷懒,从明天开始每天都拿出一个小时来看做题学知识点吧,也算给自己立一个flag,希望自己能坚持下去,再不努力就真的成咸鱼了呀。



[align=left] [/align]
[align=left]
[/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: