Codeforces Round #450 (Div. 2)ABC
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105).
The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower).
3
1 1
-1 -1
2 -1
Yes
4
1 1
2 2
-1 1
-2 2
No
3
1 2
2 1
4 60
Yes
In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed.
是否存在删除一个点后所以的点都在x=0的一侧,只要判断在两侧是否有小于2个的点就行。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int main() { 5 int n; 6 int ans = 0, ans1 = 0; 7 cin >> n; 8 for(int i = 0; i < n; i ++) { 9 int x, y; 10 cin >> x >> y; 11 if(x < 0) ans++; 12 else ans1++; 13 } 14 if(ans <= 1 || ans1 <= 1) printf("Yes\n"); 15 else printf("No\n"); 16 return 0; 17 }
You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.
The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).
Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.
1 2 0
2
2 3 7
-1
The fraction in the first example has the following decimal notation: . The first zero stands on second position.
The fraction in the second example has the following decimal notation: . There is no digit 7 in decimal notation of the fraction.
判断c是在a/b的十进制中的小数第几位,没有就输出-1. 主要是模拟除法。
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() { 4 int a, b, c, cnt = 0; 5 cin >> a >> b >> c; 6 a %= b; 7 for(int i = 0; i < 1000; i ++) { 8 if(a*10 < b && c == 0) return 0*printf("%d\n",cnt+1); 9 while(a < b) { 10 a*= 10,cnt++; 11 } 12 13 int tmp = a/b; 14 if(tmp == c) return 0*printf("%d\n",cnt); 15 a -= tmp*b; 16 if(a == 0) { 17 if(c == 0) return 0*printf("%d\n",cnt+1); 18 break; 19 } 20 } 21 printf("-1\n"); 22 return 0; 23 }
You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.
We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j < i) the following holds: aj < ai.
The first line contains the only integer n (1 ≤ n ≤ 105) — the length of the permutation.
The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation. All the integers are distinct.
Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.
1
1
1
5
5 1 2 3 4
5
In the first example the only element can be removed.
求删掉哪个数可以使的record数量最大,换句话来说就是删除哪个数可以增加的record最多。
在当前元素a[i]时有三种情况。max1为a[i]前面的最大值,max2为a[i]前面的次大值。
一、max2 < max1 < a[i] 删除a[i]的话会使得record减一
二、max2 < a[i] < max1 输出a[i]既不会增加也不会减少,但删除max1会使得a[i]变成record。
三、a[i] < max1 < max2 删除哪一个都不会有影响。
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N = 1e5+10; 4 int a[N], cnt[N]; 5 vector<int> vs; 6 int main() { 7 int n; 8 int max1 = 0, max2 = 0; 9 cin >> n; 10 for(int i = 1; i <= n; i++) { 11 cin >> a[i]; 12 if(max1 < a[i]) { 13 max2 = max1; 14 max1 = a[i]; 15 cnt[a[i]]--; 16 } else if(max2 < a[i]) { 17 cnt[max1]++; 18 max2 = a[i]; 19 } 20 } 21 int MAX = -1000000, ans = 0; 22 for(int i = 1; i <= n; i ++) { 23 if(cnt[i] > MAX) { 24 ans = i; 25 MAX = cnt[i]; 26 } 27 } 28 printf("%d\n",ans); 29 return 0; 30 }