3-1Sqrt Bo
Problem Description
Let's define the function
f(n)=⌊n−−√⌋
.
Bo wanted to know the minimum number y which satisfies fy(n)=1 .
note: f1(n)=f(n),fy(n)=f(fy−1(n))
It is a pity that Bo can only use 1 unit of time to calculate this function each time.
And Bo is impatient, he cannot stand waiting for longer than 5 units of time.
So Bo wants to know if he can solve this problem in 5 units of time.
Bo wanted to know the minimum number y which satisfies fy(n)=1 .
note: f1(n)=f(n),fy(n)=f(fy−1(n))
It is a pity that Bo can only use 1 unit of time to calculate this function each time.
And Bo is impatient, he cannot stand waiting for longer than 5 units of time.
So Bo wants to know if he can solve this problem in 5 units of time.
Input
This problem has multi test cases(no more than
120
).
Each test case contains a non-negative integer n(n<10100) .
Each test case contains a non-negative integer n(n<10100) .
Output
For each test case print a integer - the answer
y
or a string "TAT" - Bo can't solve this problem.
Sample Input
233 233333333333333333333333333333333333333333333333333333333
Sample Output
3 TAT
tips :就做了这么一道题,而且当时竟然还没有思路。相当于给一个很大很大的数。判断能否在5次之内不停开方得到的整数下界为1。我最终的想法还是找了规律,例如、开五次方得到1的最大值是2^32-1。
Why?试想比二小一点的数下界不就是一了吗,所以根号2是一次,2^2需要两次,4^2需要三次,以此类推。
然后处理数据时也耽误时间了。本来是商量好思路就让队友写的,其实这也就是很简单的大数,甚至比以前的大数都要简单。直接以字符串的形式读的,一直控制在 long long范围内,最后直接上if判断,感觉还是挺快的。队友竟然用了java还wa了两次,比较难过。唉~
code:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
string a;
while(cin>>a)
{
if(a.length()>10)
cout<<"TAT"<<endl;
else
{
long long shu=0;
long long linshi=1;
for(int i=a.length()-1;i>=0;i--)
{
shu+=(a[i]-'0')*linshi;
linshi*=10;
}
if(shu>=1&&shu<4)
cout<<1<<endl;
else if(shu>=4&&shu<16)
cout<<2<<endl;
else if(shu>=16&&shu<256)
cout<<3<<endl;
else if(shu>=256&&shu<65536)
cout<<4<<endl;
else if(shu>=65536&&shu<4294967296)
cout<<5<<endl;
else
cout<<"TAT"<<endl;
}
}
}
3-10Rower Bo
Problem Description
There is a river on the Cartesian coordinate system,the river is flowing along the x-axis direction.
Rower Bo is placed at (0,a) at first.He wants to get to origin (0,0) by boat.Boat speed relative to water is v1 ,and the speed of the water flow is v2 .He will adjust the direction of v1 to origin all the time.
Your task is to calculate how much time he will use to get to origin.Your answer should be rounded to four decimal places.
If he can't arrive origin anyway,print"Infinity"(without quotation marks).
Rower Bo is placed at (0,a) at first.He wants to get to origin (0,0) by boat.Boat speed relative to water is v1 ,and the speed of the water flow is v2 .He will adjust the direction of v1 to origin all the time.
Your task is to calculate how much time he will use to get to origin.Your answer should be rounded to four decimal places.
If he can't arrive origin anyway,print"Infinity"(without quotation marks).
Input
There are several test cases. (no more than 1000)
For each test case,there is only one line containing three integers a,v1,v2 .
0≤a≤100 , 0≤v1,v2,≤100 , a,v1,v2 are integers
For each test case,there is only one line containing three integers a,v1,v2 .
0≤a≤100 , 0≤v1,v2,≤100 , a,v1,v2 are integers
Output
For each test case,print a string or a real number.
If the absolute error between your answer and the standard answer is no more than 10−4 , your solution will be accepted.
If the absolute error between your answer and the standard answer is no more than 10−4 , your solution will be accepted.
Sample Input
2 3 3 2 4 3
Sample Output
Infinity 1.1428571429
tips :中学物理题,怀念吧。一直找规律,没找到,这也不能怪别人。做题多了当然规律也更容易看,其实正解是解微分方程。说实话还是有难度的。但是最后的结果是真TMD的简单啊,t=a*v1/(v1^2-v2^2)。感兴趣的自己看看大神的解释。
1010 Rower Bo
首先这个题微分方程强解显然是可以的,但是可以发现如果设参比较巧妙就能得到很方便的做法。
先分解v1,
设船到原点的距离是r,容易列出方程
dtdr=v2cosθ−v1
dtdx=v2−v1cosθ
上下界都是清晰的,定积分一下:
0−a=v2∫0Tcosθdt−v1T
0−0=v2T−v1∫0Tcosθdt
直接把第一个式子代到第二个里面
v2T=v2v1(−a+v1T)
T=v12−v22v1a
这样就很Simple地解完了,到达不了的情况就是v1<v2(或者a>0且v1=v2)。
代码没必要上了,直接套公式。
Teacher Bo
Problem Description
Teacher BoBo is a geography teacher in the school.One day in his class,he marked
N
points in the map,the
i
-th point is at
(Xi,Yi)
.He wonders,whether there is a tetrad
(A,B,C,D)(A<B,C<D,A≠CorB≠D)
such that the manhattan distance between A and B is equal to the manhattan distance between C and D.
If there exists such tetrad,print "YES",else print "NO".
If there exists such tetrad,print "YES",else print "NO".
Input
First line, an integer
T
. There are
T
test cases.
(T≤50)
In each test case,the first line contains two intergers, N, M, means the number of points and the range of the coordinates. (N,M≤105) .
Next N lines, the i -th line shows the coordinate of the i -th point. (Xi,Yi)(0≤Xi,Yi≤M) .
In each test case,the first line contains two intergers, N, M, means the number of points and the range of the coordinates. (N,M≤105) .
Next N lines, the i -th line shows the coordinate of the i -th point. (Xi,Yi)(0≤Xi,Yi≤M) .
Output
T
lines, each line is "YES" or "NO".
Sample Input
2 3 10 1 1 2 2 3 3 4 10 8 8 2 3 3 3 4 4
Sample Output
YES NO
code:
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
struct h
{
int x,y;
} re[100010];
int man(int i,int j)
{
int hui=abs(re[i].x-re[j].x)+abs(re[i].y-re[j].y);
return hui;
}
int main()
{
int te=0;
cin>>te;
while(te--)
{
int vis[200020]= {0};
int sum,jie=0;
int shao=0;
cin>>sum>>jie;
for(int i=0; i<sum; i++)
{
cin>>re[i].x>>re[i].y;
if(i==0||shao==1)
continue;
for(int j=0; j<i; j++)
{
if(vis[man(i,j)]==0)
vis[man(i,j)]=1;
else
{
shao=1;
break;
}
}
}
if(shao==0)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
}
http://acm.hdu.edu.cn/
这是最近打多校的题,没参加的去这个网址上,problems Arc上面最后一页的就是最新的这几道题。还是挺有意思的,估计看这篇博客应该都是没打的吧,打的都去看大神的题解了。
继续努力,好好学习!