[关闭]
@Dmaxiya 2018-08-17T10:30:19.000000Z 字数 2977 阅读 953

Codeforces Round #450(Div.2)

Codeforces


Contests 链接:Codeforces Round #450(Div.2)
过题数:3
排名:808/4629

A. Find Extra One

题意

给定平面直角坐标系上 个点的坐标,数据保证没有点在 轴上,问,是否存在这样一个点 ,删掉 之后,剩下的所有点,都在 轴的一侧。

数据范围

题解

扫一遍,记录 轴左边和右边的点的数量,如果其中一边的点的数量小于等于 ,就输出 ,否则就

过题代码

  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 <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. int n;
  21. int x, y;
  22. int cntl, cntr;
  23. int main() {
  24. #ifdef LOCAL
  25. freopen("test.txt", "r", stdin);
  26. // freopen("out.txt", "w", stdout);
  27. #endif // LOCAL
  28. // ios::sync_with_stdio(false);
  29. while(scanf("%d", &n) != EOF) {
  30. cntl = cntr = 0;
  31. for(int i = 0; i < n; ++i) {
  32. scanf("%d%d", &x, &y);
  33. if(x > 0) {
  34. ++cntr;
  35. } else {
  36. ++cntl;
  37. }
  38. }
  39. if(cntl == 0 || cntl == 1) {
  40. printf("Yes\n");
  41. } else if(cntr == 0 || cntr == 1) {
  42. printf("Yes\n");
  43. } else {
  44. printf("No\n");
  45. }
  46. }
  47. return 0;
  48. }

B. Position in Fraction

题意

给定三个数字 ,求数字 在有理数 小数点后第几位,如果不存在,则输出

数据范围

题解

模拟除法计算即可,根据抽屉原理, ,在取模的过程中,取模的次数超过 ,就一定会取到相同的数字,所以最多做 次除法,就可以判断 是否在 的小数位中。

过题代码

  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 <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. long long a, b, c;
  21. int main() {
  22. #ifdef LOCAL
  23. freopen("test.txt", "r", stdin);
  24. // freopen("out.txt", "w", stdout);
  25. #endif // LOCAL
  26. // ios::sync_with_stdio(false);
  27. while(cin >> a >> b >> c) {
  28. int ans = -1;
  29. a = a % b;
  30. for(int i = 1; i <= b; ++i) {
  31. LL tmp = a * 10 / b;
  32. if(tmp == c) {
  33. ans = i;
  34. break;
  35. }
  36. a = a * 10 % b;
  37. }
  38. cout << ans << endl;
  39. }
  40. return 0;
  41. }

C. Remove Extra One

题意

给定一个 个数字的排列,要删掉其中一个数字,使得这个排列中的 数最多, 数需要满足以下条件:
对于排列 ,如果存在一下标 对于任意的 ,都有 ,那么数字 就是一个 数。

数据范围

题解

计算删掉每个数字 后,对整个数列的 数的个数的贡献,如果 ,则删掉 后,对整个数列的贡献 ,如果 中的最大值,而 是其中的次大值,则删掉 后,对整个数列的贡献 ,最后跑一边,取贡献的最大值。

过题代码

  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 <functional>
  17. #include <iomanip>
  18. using namespace std;
  19. #define LL long long
  20. const int maxn = 100000 + 100;
  21. int n, ans;
  22. int num[maxn];
  23. set<int> st;
  24. set<int>::iterator it;
  25. int Time[maxn];
  26. int main() {
  27. #ifdef LOCAL
  28. freopen("test.txt", "r", stdin);
  29. // freopen("out.txt", "w", stdout);
  30. #endif // LOCAL
  31. // ios::sync_with_stdio(false);
  32. while(scanf("%d", &n) != EOF) {
  33. st.clear();
  34. memset(Time, 0, sizeof(Time));
  35. for(int i = 1; i <= n; ++i) {
  36. scanf("%d", &num[i]);
  37. }
  38. st.insert(num[1]);
  39. --Time[num[1]];
  40. for(int i = 2; i <= n; ++i) {
  41. st.insert(num[i]);
  42. it = st.end();
  43. --it;
  44. if(*it == num[i]) {
  45. --Time[*it];
  46. continue;
  47. }
  48. --it;
  49. if(*it == num[i]) {
  50. ++it;
  51. ++Time[*it];
  52. }
  53. }
  54. int Max = Time[1];
  55. ans = 1;
  56. for(int i = 2; i <= n; ++i) {
  57. if(Time[i] > Max) {
  58. Max = Time[i];
  59. ans = i;
  60. }
  61. }
  62. printf("%d\n", ans);
  63. }
  64. return 0;
  65. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注