目录:
A:log2(N)
B:如何溜的最快
C : 200和整数对之间的情缘
D : 两面包夹芝士
E : 构造回文串
F : 模拟计算器
G : 排队援救
H : 括号匹配
A:log2(N)
Description
给你一个数N,请你找出最大的的整数k,满足 2k ≤ N
Input
1 ≤ N ≤ 1018
Output
输出k并换行
Sample Input
6
Sample Output
2
Hint
注意精度问题
PS:1.不能用pow()和log(),他们基于浮点运算,浮点的运算精度不足。2.注意输入变量的类型需要定义为long long。3.当输入有多组数据时需要用while(cin>>n)
#include<iostream>
using namespace std;
int main()
{
long long n;
cin >> n;
int k = 0;
while (n != 1)
{
n /= 2; k++;
}
cout << k;
return 0;
}
B:如何溜的最快
Description
给你一个终点(x,y),从(0,0)出发,每步可以向任意方向沿直线走 恰好为R 的距离,请你输出到达终点所需的最短步数。
Input
多组数据,每组数据输入R,x,y
1 ≤ R ≤ 105
0 ≤ x, y ≤ 105
(x,y)≠(0,0)
所有输入皆为int型
Output
输出结果并换行
Sample Input
3 4 4
2 1 1
2 2 2
Sample Output
2
2
2
Hint
距离不能恰好走到的情况,可以走折线到达
PS:1.第一种情况r大于dis(dis=pow(x*x+y*y,0.5)),步数为二,相当于一个三角形。2.第二种情况刚好到达步数就为一。 3.第三种情况,r<dis
Attention!!!!! 当dis>r的时候,要分情况讨论,因为能整除和不能整除时走的步数不一样
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int r, x, y;
while (cin >> r >> x >> y)
{
double dis = sqrt(x * x + y * y);
if (dis < r)
cout << 2<<endl;