[关闭]
@Dmaxiya 2018-08-17T02:17:34.000000Z 字数 3445 阅读 1521

Codeforces Round #465 (Div. 2)

Codeforces


Contests 链接:Codeforces Round #465 (Div. 2)
过题数:3
排名:1072/10985

A. Fafa and his Company

题意

有 个人,从 个人中选出一些人作为领导,管理其他所有人,要求每个领导管理的人数相等,问有多少种选领导的方式。

输入

输入包含一个整数 。

输出

输出方案数。

样例

输入 输出 提示
2 1
10 3 可以有以下三种方案:
选出 个人领导其他 个人;
选出 个人,每人领导 个人;
选出 个人,每人领导 个人。

题解

相当于将 个人平均分组,每组至少两人,问有多少种分法,暴力枚举。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <sstream>
  17. using namespace std;
  18. #define LL long long
  19. int n;
  20. int main() {
  21. #ifdef Dmaxiya
  22. freopen("test.txt", "r", stdin);
  23. #endif // Dmaxiya
  24. ios::sync_with_stdio(false);
  25. while(scanf("%d", &n) != EOF) {
  26. int ans = 0;
  27. for(int i = 2; i <= n; ++i) {
  28. if(n % i == 0) {
  29. ++ans;
  30. }
  31. }
  32. printf("%d\n", ans);
  33. }
  34. return 0;
  35. }

B. Fafa and the Gates

题意

在一个平面直角坐标系内,初始 的坐标为 ,接着他会按照一个长度为 的字符串的指令来走,假设当前 的位置为 ,字符串的第 个字符为 'U' 时, 将移动到 ,为 'R' 时移动到 ,问在移动的过程中穿过直线 的次数。

输入

第一行为一个整数 ,第二行为一个长度为 的字符串 ,字符串内的每个字符 。

输出

输出穿过 的次数。

样例

输入 输出 提示
1
U
0
6
RURUUR
1
7
URRRUUU
2 移动路线如下图:

题解

按题意模拟,每当 时判断当前行走方向是否和下一步方向相同,如果相同则穿过这条直线一次。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <sstream>
  17. using namespace std;
  18. #define LL long long
  19. const int maxn = 100000 + 100;
  20. int n;
  21. char str[maxn];
  22. int main() {
  23. #ifdef Dmaxiya
  24. freopen("test.txt", "r", stdin);
  25. #endif // Dmaxiya
  26. ios::sync_with_stdio(false);
  27. while(scanf("%d%s", &n, str) != EOF) {
  28. int ans = 0;
  29. int x = 0, y = 0;
  30. for(int i = 0; i < n; ++i) {
  31. if(str[i] == 'U') {
  32. ++y;
  33. } else {
  34. ++x;
  35. }
  36. if(x == y) {
  37. if(str[i] == str[i + 1]) {
  38. ++ans;
  39. }
  40. }
  41. }
  42. printf("%d\n", ans);
  43. }
  44. return 0;
  45. }

C. Fifa and Fafa

题意

在平面直角坐标系内,有一个圆心为 ,半径为 的圆,还有一个点 ,要求在圆内找到一个圆,使得这个圆不包含点 且面积最大。

输入

输入包含五个整数 。

输出

输出满足题意的圆的圆心坐标和半径,误差在 内即认为答案正确,如果有多解输出任意一个。

样例

输入 输出
5 3 3 1 1 3.7677669529663684 3.7677669529663684 3.914213562373095
10 5 5 5 15 5.0 5.0 10.0

题解

如果点在圆外,就可以直接输出圆的圆心和半径,否则:
经过点 的直线倾斜角为 (注意 的倾斜角特判为 ),则该直线与圆的交点为 ,取使 与 大的那个点 ,则最终圆的圆心为 ,然后就可以算出半径。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <bitset>
  15. #include <algorithm>
  16. #include <sstream>
  17. using namespace std;
  18. #define LL long long
  19. const double PI = acos(-1.0);
  20. double theta;
  21. LL R, xx1, xx2, yy1, yy2;
  22. double lx, rx, ly, ry, ansx, ansy, ansr;
  23. double dis(double x1, double y1, double x2, double y2) {
  24. return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  25. }
  26. int main() {
  27. #ifdef Dmaxiya
  28. freopen("test.txt", "r", stdin);
  29. #endif // Dmaxiya
  30. ios::sync_with_stdio(false);
  31. while(scanf("%I64d%I64d%I64d%I64d%I64d", &R, &xx1, &yy1, &xx2, &yy2) != EOF) {
  32. if(dis(xx1, yy1, xx2, yy2) >= R) {
  33. printf("%I64d %I64d %I64d\n", xx1, yy1, R);
  34. continue;
  35. }
  36. if(xx1 == xx2) {
  37. theta = PI / 2;
  38. } else {
  39. theta = atan((double)(yy1 - yy2) / (xx1 - xx2));
  40. }
  41. lx = R * cos(theta) + xx1;
  42. ly = R * sin(theta) + yy1;
  43. rx = -R * cos(theta) + xx1;
  44. ry = -R * sin(theta) + yy1;
  45. if(dis(lx, ly, xx2, yy2) < dis(rx, ry, xx2, yy2)) {
  46. ansx = (xx2 + rx) / 2;
  47. ansy = (yy2 + ry) / 2;
  48. ansr = dis(rx, ry, xx2, yy2) / 2;
  49. } else {
  50. ansx = (xx2 + lx) / 2;
  51. ansy = (yy2 + ly) / 2;
  52. ansr = dis(lx, ly, xx2, yy2) / 2;
  53. }
  54. printf("%.10f %.10f %.10f\n", ansx, ansy, ansr);
  55. }
  56. return 0;
  57. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注