2017-5-22-Train:Educational Codeforces Round 2

B. Queries about less or equal elements(二分)

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 }

C. Make Palindrome(贪心 + 模拟)

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 }

D. Area of Two Circles‘ Intersection(圆的公共面积)

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 }

时间: 2024-10-25 22:09:00

2017-5-22-Train:Educational Codeforces Round 2的相关文章

Educational Codeforces Round 22 E. Army Creation(主席树)

题目链接:Educational Codeforces Round 22 E. Army Creation 题意: 给你n个数和一个数k,然后有q个询问. 每个询问 有一个区间[l,r],问你这个区间内在满足每一种数不超过k的情况下,最大能选多少个数出来. 强制在线. 题解: 一看就要用到主席树,和主席数求区间内有多少不同的数的个数处理方法相同. 依次将每个数插入,当这个数出现的个数等于k了,就把最前面的那个数删掉. 然后询问就访问root[r]就行了. 第一次写完数据结构没有调试一遍过样例,一

Educational Codeforces Round 21 G. Anthem of Berland(dp+kmp)

题目链接:Educational Codeforces Round 21 G. Anthem of Berland 题意: 给你两个字符串,第一个字符串包含问号,问号可以变成任意字符串. 问你第一个字符串最多包含多少个第二个字符串. 题解: 考虑dp[i][j],表示当前考虑到第一个串的第i位,已经匹配到第二个字符串的第j位. 这样的话复杂度为26*n*m*O(fail). fail可以用kmp进行预处理,将26个字母全部处理出来,这样复杂度就变成了26*n*m. 状态转移看代码(就是一个kmp

Educational Codeforces Round 26 D. Round Subset(dp)

题目链接:Educational Codeforces Round 26 D. Round Subset 题意: 给你n个数,让你选其中的k个数,使得这k个数的乘积的末尾的0的个数最大. 题解: 显然,末尾乘积0的个数和因子2和因子5的个数有关. 然后考虑dp[i][j]表示选i个数,当前因子5的个数为j时,能得到因子2最多的为多少. 那么对于每个数,记录一下因子2和5的个数,做一些01背包就行了. 1 #include<bits/stdc++.h> 2 #define mst(a,b) me

Educational Codeforces Round 23 F. MEX Queries(线段树)

题目链接:Educational Codeforces Round 23 F. MEX Queries 题意: 一共有n个操作. 1.  将[l,r]区间的数标记为1. 2.  将[l,r]区间的数标记为0. 3.  将[l,r]区间取反. 对每个操作,输出标记为0的最小正整数. 题解: hash后,用线段树xjb标记一下就行了. 1 #include<bits/stdc++.h> 2 #define ls l,m,rt<<1 3 #define rs m+1,r,rt<&l

Educational Codeforces Round 25 F. String Compression(kmp+dp)

题目链接:Educational Codeforces Round 25 F. String Compression 题意: 给你一个字符串,让你压缩,问压缩后最小的长度是多少. 压缩的形式为x(...)x(...)  x表示(...)这个出现的次数. 题解: 考虑dp[i]表示前i个字符压缩后的最小长度. 转移方程解释看代码,这里要用到kmp来找最小的循环节. 当然还有一种找循环节的方式就是预处理lcp,然后通过枚举循环节的方式. 这里我用的kmp找的循环节.复杂度严格n2. 1 #inclu

Educational Codeforces Round 23 E. Choosing The Commander (trie)

题目链接: Educational Codeforces Round 23 E. Choosing The Commander 题意: 一共有n个操作. 1.  插入一个数p 2.  删除一个数p 3.  询问有多少个数 使得 x^p<l 题解: 对于前两种操作用01trie就能解决. 对于对三个操作,我们考虑在trie上搜索. 1.  当l的bit位是1时,那边bit位是p的字数全部的数都会小于l,(因为p^p=0) 2.  当l的bit为是0时,那边只能向bit位是p的子树中搜. 这样算下来

Educational Codeforces Round 21 D. Array Division

题目链接:Educational Codeforces Round 21 D. Array Division 题意: 给你n个数,现在你可以改变1<=个数的位置,然后问你是否存在有一个k,使得sum(a[i])(1<=i<=k)==sum(a[j])(k+1<=j<=n) 题解: 分析: 如果需要将一个数移动,无非就是将这个数从第一部分移到第二部分,或者从第二部分移到第一部分. 所以,我们只需要开两个map来记录一下两部分有哪些数. 当两部分的差值/2等于其中一部分的一个数时

Educational Codeforces Round 24 F. Level Generation(三分)

题目链接:Educational Codeforces Round 24 F. Level Generation 题意: 给你n个点,让你构造ans条边,使得这ans条边中至少有一半是桥. 让你求ans的最大值. 题解: 首先我们将每一个点按顺序连起来,那么可以构成n-1个桥. 然后我们可以把其中的x个点拿出来连边,这些边都不是桥. x个点最多能连x*(x-1)条边,然后剩下的n-x个点连的边将会构成桥. 然后就可以构造一个函数关系,详见check函数,然后三分一下就行了. 1 #include

Educational Codeforces Round 21 F. Card Game(网络流之最大点权独立集)

题目链接:Educational Codeforces Round 21 F. Card Game 题意: 有n个卡片,每个卡片有三个值:p,c,l; 现在让你找一个最小的L,使得满足选出来的卡片l<=L,并且所有卡片的p的和不小于k. 选择卡片时有限制,任意两张卡片的c之和不能为质数. 题解: 和hdu 1565 方格取数(2)一样,都是求最大点权独立集. 不难看出来,这题再多一个二分. 注意的是在构造二部图的时候,按照c值的奇偶性构造. 当c==1时要单独处理,因为如果有多个c==1的卡片,

Educational Codeforces Round 25 G. Tree Queries

题目链接:Educational Codeforces Round 25 G. Tree Queries 题意: 给你一棵树,一开始所有的点全是黑色,有两种操作. 1 x 将x这个点变为黑色,保证第一个操作是这个. 2 x 询问x到任意黑色的点的简单路径上的最小节点编号. 题解: 首先将一个变为黑色的点当成树根,然后dfs一下,预处理出所有点的答案. 然后开一个变量记录一下当前变黑的点的答案cur=min(cur,dp[x]). 每次询问的时候答案就是min(cur,dp[x]). 如果觉得很神