@Dmaxiya
2018-08-17T02:17:34.000000Z
字数 3445
阅读 1170
Codeforces
Contests 链接:Codeforces Round #465 (Div. 2)
过题数:3
排名:1072/10985
有 个人,从 个人中选出一些人作为领导,管理其他所有人,要求每个领导管理的人数相等,问有多少种选领导的方式。
输入包含一个整数 。
输出方案数。
| 输入 | 输出 | 提示 |
|---|---|---|
| 2 | 1 | |
| 10 | 3 | 可以有以下三种方案: 选出 个人领导其他 个人; 选出 个人,每人领导 个人; 选出 个人,每人领导 个人。 |
相当于将 个人平均分组,每组至少两人,问有多少种分法,暴力枚举。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>#include <sstream>using namespace std;#define LL long longint n;int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%d", &n) != EOF) {int ans = 0;for(int i = 2; i <= n; ++i) {if(n % i == 0) {++ans;}}printf("%d\n", ans);}return 0;}
在一个平面直角坐标系内,初始 的坐标为 ,接着他会按照一个长度为 的字符串的指令来走,假设当前 的位置为 ,字符串的第 个字符为 'U' 时, 将移动到 ,为 'R' 时移动到 ,问在移动的过程中穿过直线 的次数。
第一行为一个整数 ,第二行为一个长度为 的字符串 ,字符串内的每个字符 。
输出穿过 的次数。
| 输入 | 输出 | 提示 |
|---|---|---|
| 1 U |
0 | |
| 6 RURUUR |
1 | |
| 7 URRRUUU |
2 | 移动路线如下图:![]() |
按题意模拟,每当 时判断当前行走方向是否和下一步方向相同,如果相同则穿过这条直线一次。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>#include <sstream>using namespace std;#define LL long longconst int maxn = 100000 + 100;int n;char str[maxn];int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%d%s", &n, str) != EOF) {int ans = 0;int x = 0, y = 0;for(int i = 0; i < n; ++i) {if(str[i] == 'U') {++y;} else {++x;}if(x == y) {if(str[i] == str[i + 1]) {++ans;}}}printf("%d\n", ans);}return 0;}
在平面直角坐标系内,有一个圆心为 ,半径为 的圆,还有一个点 ,要求在圆内找到一个圆,使得这个圆不包含点 且面积最大。
输入包含五个整数 。
输出满足题意的圆的圆心坐标和半径,误差在 内即认为答案正确,如果有多解输出任意一个。
| 输入 | 输出 |
|---|---|
| 5 3 3 1 1 | 3.7677669529663684 3.7677669529663684 3.914213562373095 |
| 10 5 5 5 15 | 5.0 5.0 10.0 |
如果点在圆外,就可以直接输出圆的圆心和半径,否则:
经过点 的直线倾斜角为 (注意 的倾斜角特判为 ),则该直线与圆的交点为 ,取使 与 大的那个点 ,则最终圆的圆心为 ,然后就可以算出半径。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>#include <sstream>using namespace std;#define LL long longconst double PI = acos(-1.0);double theta;LL R, xx1, xx2, yy1, yy2;double lx, rx, ly, ry, ansx, ansy, ansr;double dis(double x1, double y1, double x2, double y2) {return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%I64d%I64d%I64d%I64d%I64d", &R, &xx1, &yy1, &xx2, &yy2) != EOF) {if(dis(xx1, yy1, xx2, yy2) >= R) {printf("%I64d %I64d %I64d\n", xx1, yy1, R);continue;}if(xx1 == xx2) {theta = PI / 2;} else {theta = atan((double)(yy1 - yy2) / (xx1 - xx2));}lx = R * cos(theta) + xx1;ly = R * sin(theta) + yy1;rx = -R * cos(theta) + xx1;ry = -R * sin(theta) + yy1;if(dis(lx, ly, xx2, yy2) < dis(rx, ry, xx2, yy2)) {ansx = (xx2 + rx) / 2;ansy = (yy2 + ry) / 2;ansr = dis(rx, ry, xx2, yy2) / 2;} else {ansx = (xx2 + lx) / 2;ansy = (yy2 + ly) / 2;ansr = dis(lx, ly, xx2, yy2) / 2;}printf("%.10f %.10f %.10f\n", ansx, ansy, ansr);}return 0;}