2017-5-22-Train:Educational Codeforces Round 2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017-5-22-Train:Educational Codeforces Round 2相关的知识,希望对你有一定的参考价值。
You are given two arrays of integers a and b. For each element of the second array b**j you should find the number of elements in array athat are less than or equal to the value b**j.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b.
The second line contains n integers — the elements of array a ( - 109 ≤ a**i ≤ 109).
The third line contains m integers — the elements of array b ( - 109 ≤ b**j ≤ 109).
Output
Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value b**j.
Examples
input
5 4 1 3 5 7 9 6 4 2 8
output
3 2 1 4
input
5 5 1 2 1 2 5 3 1 4 1 5
output
4 2 4 2 5
Means:
在A数组中找到小于等于b[i]的个数
Solve:
直接二分美滋滋
Code:
1 #pragma comment(linker, "/STACK:36777216") 2 3 #include <bits/stdc++.h> 4 using namespace std; 5 #define LSON id << 1 , l , mid 6 #define RSON id << 1 | 1 , mid + 1 , r 7 #define ROOT 1 , 1 , n 8 #define CLR(x , y) memset(x , y , sizeof(x)) 9 #define LOWBIT(x) x & (-x) 10 #define FORN(i , a , n) for(int i = (a) ; i <= (n) ; ++i) 11 #define FORP(i , n , a) for(int i = (n) ; i >= (a) ; --i) 12 #define CASE(x) printf("Case %d: ", x) 13 #define SFD(x) scanf("%lf" , &x) 14 #define SFC(x) scanf(" %c" , &x) 15 #define SFS(x) scanf(" %s" , x) 16 #define SFI(x) scanf("%d" , &x) 17 #define SFI64(x) scanf("%I64d" , &x) 18 #define PFF(x) printf("%f" , x) 19 #define PFD(x) printf("%lf" , x) 20 #define PFI(x) printf("%d" , x) 21 #define PFC(x) printf("%c" , x) 22 #define PFS(x) printf("%s" , x) 23 #define PFI64(x) printf("%I64d" , x) 24 #define SPACE printf(" ") 25 #define PUT puts("") 26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i) 27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i) 28 #define PB(x) push_back(x) 29 #define ALL(A) A.begin(), A.end() 30 #define SZ(A) int((A).size()) 31 #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) 32 #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) 33 #define LOCAL 34 static const double PI = acos(-1.0); 35 static const double EPS = 1e-8; 36 static const int INF = 0X3fffffff; 37 typedef long long LL; 38 typedef double DB; 39 int read() 40 { 41 int x = 0; 42 int f = 1 ; char ch = getchar(); 43 while (ch < ‘0‘ || ch > ‘9‘) {if (ch == ‘-‘) f = -1; ch = getchar();} 44 while (ch >= ‘0‘ && ch <= ‘9‘) {x = x * 10 + ch - ‘0‘; ch = getchar();} 45 x *= f; 46 return x; 47 } 48 49 inline void write(int x) 50 { 51 int y = 10 , len = 1; 52 while(y <= x) 53 { 54 y *= 10; 55 ++len; 56 } 57 while(len--) 58 { 59 y /= 10; 60 putchar(x / y + 48); 61 x %= y; 62 } 63 } 64 65 /************************Little Pea****************************/ 66 67 static const int MAXN = 2e5 + 10; 68 int a[MAXN]; 69 int n , m; 70 int main() 71 { 72 #ifndef ONLINE_JUDGE 73 freopen("D:\\\\系统优化\\\\Desktop\\\\littlepea\\\\in.data" , "r" , stdin); 74 #endif 75 scanf("%d%d" , &n , &m); 76 for(int i = 1 ; i <= n ; ++i) 77 { 78 scanf("%d" , a + i); 79 } 80 81 sort(a + 1 , a + 1 + n); 82 83 while(m--) 84 { 85 int x; 86 scanf("%d" , &x); 87 88 printf("%d " , upper_bound(a + 1 , a + 1 + n , x) - a - 1); 89 90 91 } 92 93 #ifndef ONLINE_JUDGE 94 fclose(stdin), fclose(stdout); 95 #endif 96 }
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn‘t change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn‘t count as changes.
You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically.
Input
The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.
Output
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
Examples
input
aabc
output
abba
input
aabcd
output
abcba
Means:
给出字符串s,通过调整顺序或修改字符使字符串回文,输出修改次数最小且字典序最小的回文字符串。
Solve:
统计一下字母次数,字母序后的出现次数奇数的改成字母序小的,然后贪心选能使用的最小字符构建回文字符串即可
Code:
1 #pragma comment(linker, "/STACK:36777216") 2 3 #include <bits/stdc++.h> 4 using namespace std; 5 #define LSON id << 1 , l , mid 6 #define RSON id << 1 | 1 , mid + 1 , r 7 #define ROOT 1 , 1 , n 8 #define CLR(x , y) memset(x , y , sizeof(x)) 9 #define LOWBIT(x) x & (-x) 10 #define FORN(i , a , n) for(int i = (a) ; i <= (n) ; ++i) 11 #define FORP(i , n , a) for(int i = (n) ; i >= (a) ; --i) 12 #define CASE(x) printf("Case %d: ", x) 13 #define SFD(x) scanf("%lf" , &x) 14 #define SFC(x) scanf(" %c" , &x) 15 #define SFS(x) scanf(" %s" , x) 16 #define SFI(x) scanf("%d" , &x) 17 #define SFI64(x) scanf("%I64d" , &x) 18 #define PFF(x) printf("%f" , x) 19 #define PFD(x) printf("%lf" , x) 20 #define PFI(x) printf("%d" , x) 21 #define PFC(x) printf("%c" , x) 22 #define PFS(x) printf("%s" , x) 23 #define PFI64(x) printf("%I64d" , x) 24 #define SPACE printf(" ") 25 #define PUT puts("") 26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i) 27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i) 28 #define PB(x) push_back(x) 29 #define ALL(A) A.begin(), A.end() 30 #define SZ(A) int((A).size()) 31 #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) 32 #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) 33 #define LOCAL 34 static const double PI = acos(-1.0); 35 static const double EPS = 1e-8; 36 static const int INF = 0X3fffffff; 37 typedef long long LL; 38 typedef double DB; 39 int read() 40 { 41 int x = 0; 42 int f = 1 ; char ch = getchar(); 43 while (ch < ‘0‘ || ch > ‘9‘) {if (ch == ‘-‘) f = -1; ch = getchar();} 44 while (ch >= ‘0‘ && ch <= ‘9‘) {x = x * 10 + ch - ‘0‘; ch = getchar();} 45 x *= f; 46 return x; 47 } 48 49 inline void write(int x) 50 { 51 int y = 10 , len = 1; 52 while(y <= x) 53 { 54 y *= 10; 55 ++len; 56 } 57 while(len--) 58 { 59 y /= 10; 60 putchar(x / y + 48); 61 x %= y; 62 } 63 } 64 65 /************************Little Pea****************************/ 66 67 static const int MAXN = 2e5 + 10; 68 char data[MAXN]; 69 int num[30]; 70 int n , m; 71 int main() 72 { 73 #ifndef ONLINE_JUDGE 74 freopen("D:\\\\系统优化\\\\Desktop\\\\littlepea\\\\in.data" , "r" , stdin); 75 #endif 76 scanf(" %s" , data); 77 int len = strlen(data); 78 int x = 25 , pos = 0; 79 for(int i = 0 ; i < len ; ++i) 80 ++num[data[i] - ‘a‘]; 81 for(int i = 0 ; i < 26 ; ++i) 82 { 83 if(num[i] & 1) 84 { 85 while(num[x] % 2 == 0 && i < x) 86 --x; 87 if(i == x) 88 --num[i] , data[len / 2] = i + ‘a‘; 89 else 90 --num[x] , ++num[i]; 91 } 92 93 for(int j = 0 ; j < num[i] / 2 ; ++j) 94 data[pos] = i + ‘a‘ , data[len - pos - 1] = i + ‘a‘ , ++pos; 95 } 96 97 printf("%s" , data); 98 99 100 #ifndef ONLINE_JUDGE 101 fclose(stdin), fclose(stdout); 102 #endif 103 }
You are given two circles. Find the area of their intersection.
Input
The first line contains three integers x1, y1, r1 ( - 109 ≤ x1, y1 ≤ 109, 1 ≤ r1 ≤ 109) — the position of the center and the radius of the first circle.
The second line contains three integers x2, y2, r2 ( - 109 ≤ x2, y2 ≤ 109, 1 ≤ r2 ≤ 109) — the position of the center and the radius of the second circle.
Output
Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn‘t exceed10 - 6.
Examples
input
0 0 4 6 0 4
output
7.25298806364175601379
input
0 0 5 11 0 5
output
0.00000000000000000000
Code:
1 #pragma comment(linker, "/STACK:36777216") 2 3 #include <bits/stdc++.h> 4 using namespace std; 5 #define LSON id << 1 , l , mid 6 #define RSON id << 1 | 1 , mid + 1 , r 7 #define ROOT 1 , 1 , n 8 #define CLR(x , y) memset(x , y , sizeof(x)) 9 #define LOWBIT(x) x & (-x) 10 #define FORN(i , a , n) for(int i = (a) ; i <= (n) ; ++i) 11 #define FORP(i , n , a) for(int i = (n) ; i >= (a) ; --i) 12 #define CASE(x) printf("Case %d: ", x) 13 #define SFD(x) scanf("%lf" , &x) 14 #define SFC(x) scanf(" %c" , &x) 15 #define SFS(x) scanf(" %s" , x) 16 #define SFI(x) scanf("%d" , &x) 17 #define SFI64(x) scanf("%I64d" , &x) 18 #define PFF(x) printf("%f" , x) 19 #define PFD(x) printf("%lf" , x) 20 #define PFI(x) printf("%d" , x) 21 #define PFC(x) printf("%c" , x) 22 #define PFS(x) printf("%s" , x) 23 #define PFI64(x) printf("%I64d" , x) 24 #define SPACE printf(" ") 25 #define PUT puts("") 26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i) 27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i) 28 #define PB(x) push_back(x) 29 #define ALL(A) A.begin(), A.end() 30 #define SZ(A) int((A).size()) 31 #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) 32 #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) 33 #define LOCAL 34 static const double PI = acosl(-1); 35 static const double EPS = 1e-5; 36 static const int INF = 0X3fffffff; 37 typedef long long LL; 38 typedef double DB; 39 int read() 40 { 41 int x = 0; 42 int f = 1 ; char ch = getchar(); 43 while (ch < ‘0‘ || ch > ‘9‘) {if (ch == ‘-‘) f = -1; ch = getchar();} 44 while (ch >= ‘0‘ && ch <= ‘9‘) {x = x * 10 + ch - ‘0‘; ch = getchar();} 45 x *= f; 46 return x; 47 } 48 49 inline void write(int x) 50 { 51 int y = 10 , len = 1; 52 while(y <= x) 53 { 54 y *= 10; 55 ++len; 56 } 57 while(len--) 58 { 59 y /= 10; 60 putchar(x / y + 48); 61 x %= y; 62 } 63 } 64 65 /************************Little Pea****************************/ 66 67 typedef long double LD; 68 static const int MAXN = 2e5 + 10; 69 int x1 , y1 , r1 , x2 , y2 , r2; 70 inline LL Pow(LL x) 71 { 72 return x * x; 73 } 74 double Cal() 75 { 76 double ans = 0; 77 LL dis = Pow(x1 - x2) + Pow(y1 - y2); 78 if(dis >= Pow(r1 + r2))//xiang li 79 return 0; 80 if(dis <= Pow(abs(r1 - r2))) 81 return PI * Pow(min(r1 , r2)); 82 double A1 = 2 * acosl((Pow(r1) + dis - Pow(r2)) / 2.0 / r1 / sqrt(dis)); 83 double A2 = 2 * acosl((Pow(r2) + dis - Pow(r1)) / 2.0 / r2 / sqrt(dis)); 84 ans += 0.5 * (A1 * Pow(r1) + A2 * Pow(r2)); 85 ans -= 0.5 * (sinl(A1) * Pow(r1) + sinl(A2) * Pow(r2));//s = 1 / 2 * l * l * angle 86 return ans; 87 } 88 int main() 89 { 90 #ifndef ONLINE_JUDGE 91 freopen("D:\\\\系统优化\\\\Desktop\\\\littlepea\\\\in.data" , "r" , stdin); 92 #endif 93 scanf("%d%d%d%d%d%d" , &x1 , &y1 , &r1 , &x2 , &y2 , &r2); 94 printf("%.20f" , Cal()); 95 96 #ifndef ONLINE_JUDGE 97 fclose(stdin), fclose(stdout); 98 #endif 99 }
以上是关于2017-5-22-Train:Educational Codeforces Round 2的主要内容,如果未能解决你的问题,请参考以下文章