TsinSen清橙:
-
缩小的陆地(shrinking land)
解题思路:侵蚀面积s每年增加50,当s大于由原点为圆心、房子到原点的长度为半径的圆的面积一半时,房子将受到侵蚀,增加的50的次数即第几年。
- PI的精度至少要取到3.1416,PI = 4 * atan(1.0) = 3.14159;
- printf("%.0f",z);scanf("%f %f",&x,y&); scanf("%1f %1f",&x,&y) ; //浮点数占位符,取整输出占位符。
- 使用cin cout可以忽略输入输出数据的占位符;printf("%d ",a)可以输出空格。
#include <iostream> #include <cmath> using namespace std; int main(){ float s,x,y; int t,z; cin >> t; while(t--){ z = 0; cin >> x >> y; s = ( x * x + y * y ) * 3.14159/ 2; while(z*50 <= s){ z++; } cout<<z<<endl; } return 0; }
-
集合运算
解题思路:利用list的merge() / sort() / unique() 函数快速求并集;并集中B中没有的是B在A中的差集,放入差集集合;AB中同时有的元素,放入交集集合。
- 新建数组:int A[n ] ;
- stl的list新建list < int > A;A.sort(); A.merge(B); A.push_back(); A.front();A.pop_front();
-
时间转换
解题思路:逐层减去,即先用总时间T0/3600向下取整,是H;减去小时时间H,更新总时间T1/60是分钟时间M,减去分钟时间,是最后的秒时间S;
- #include<math.h> 对除法结果用floor(number),向下取整。
-
瓷砖铺放
解题思路:可以使用斐波那契数列(递归)、动态规划(递推)两种方法 来解。