Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何

A. Vicious Keyboard
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Tonio has a keyboard with only two letters, "V" and "K".

One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.

Input

The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.

Output

Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.

Examples
Input
VK
Output
1
Input
VV
Output
1
Input
V
Output
0
Input
VKKKKKKKKKVVVVVVVVVK
Output
3
Input
KVKV
Output
1
Note

For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.

For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.

For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.

题意:给你一个串 最多只能更改一个字母 问最多能有多少个“VK”

题解:暴力判断有多少个“VK”  暴力更改某一个字符为’K‘ 或’V‘  取“VK”数量的最大值输出

 1 #include<bits/stdc++.h>
 2 #define ll __int64
 3 using namespace std;
 4 int main()
 5 {
 6     char a[105];
 7     scanf("%s",a);
 8     int len=strlen(a);
 9     int ans=0;
10     for(int i=0; i<len-1; i++)
11     {
12         if(a[i]=='V'&&a[i+1]=='K')
13             ans++;
14     }
15     for(int i=0; i<len; i++)
16     {
17         int exm=0;
18         char ww=a[i];
19         a[i]='V';
20         for(int j=0; j<len-1; j++)
21         {
22             if(a[j]=='V'&&a[j+1]=='K')
23                 exm++;
24         }
25         ans=max(ans,exm);
26         a[i]=ww;
27     }
28     for(int i=0; i<len; i++)
29     {
30         int exm=0;
31         char ww=a[i];
32         a[i]='K';
33         for(int j=0; j<len-1; j++)
34         {
35             if(a[j]=='V'&&a[j+1]=='K')
36                 exm++;
37         }
38         ans=max(ans,exm);
39         a[i]=ww;
40     }
41     printf("%d
",ans);
42     return 0;
43 }
B. Valued Keys
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.

The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.

For example, f("ab", "ba") = "aa", and f("nzwzl", "zizez") = "niwel".

You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x, z) = y, or print -1 if no such string z exists.

Input

The first line of input contains the string x.

The second line of input contains the string y.

Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.

Output

If there is no string z such that f(x, z) = y, print -1.

Otherwise, print a string z such that f(x, z) = y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.

Examples
Input
ab
aa
Output
ba
Input
nzwzl
niwel
Output
xiyez
Input
ab
ba
Output
-1
Note

The first case is from the statement.

Another solution for the second case is "zizez"

There is no solution for the third case. That is, there is no z such that f("ab", z) =  "ba".

题意:定义 f(x, z) = y  例如 f("ab", "ba") = "aa", and f("nzwzl", "zizez") = "niwel". 等长字符串,对于每一位取出较小的合并成新的字符串。

现在给你x,y输出满足条件的z 不存在则输出-1;

题解:如果y中存在某一位字符大于x中对应位置字符 则输出-1 否则输出y

 1 #include<bits/stdc++.h>
 2 #define ll __int64
 3 using namespace std;
 4 int main()
 5 {
 6     char a[105],b[105];
 7     scanf("%s %s",a,b);
 8     int len=strlen(a);
 9     for(int i=0;i<len;i++)
10     {
11         if(b[i]>a[i])
12         {
13             printf("-1
");
14             return 0;
15         }
16     }
17     printf("%s
",b);
18     return 0;
19 }
C. Voltage Keepsake
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have n devices that you want to use simultaneously.

The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.

You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.

You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.

If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.

Input

The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.

This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.

Output

If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.

Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.

Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .

Examples
Input
2 1
2 2
2 1000
Output
2.0000000000
Input
1 100
1 1
Output
-1
Input
3 5
4 3
5 2
6 1
Output
0.5000000000
Note

In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.

In sample test 2, you can use the device indefinitely.

In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.

 题意:n块电池 ai为每秒耗电量 bi为初始储电量  充电装置每秒给一个电池充p点电量 问在任意一个电池耗电完毕之前的最大持续时间

 题解:二分答案 check即可 注意精度不要开大  不然会TLE;

 1 #include<bits/stdc++.h>
 2 #define ll __int64
 3 using namespace std;
 4 ll n,p;
 5 ll a[100005],b[100005];
 6 bool check(double x)
 7 {
 8     double sum=0;
 9     for(int i=1;i<=n;i++)
10     {
11         if(a[i]*x-b[i]>=0.00000001)
12          sum+=(a[i]*x-b[i]);
13     }
14     if(sum-x*p>=0.000000001)
15       return true;
16     else
17       return false;
18 }
19 int main()
20 {
21     ll zong=0;
22     scanf("%I64d %I64d",&n,&p);
23     for(int i=1;i<=n;i++){
24       scanf("%I64d %I64d",&a[i],&b[i]);
25       zong+=a[i];
26       }
27     if(zong<=p)
28     {
29         printf("-1
");
30         return 0;
31     }
32     double l=0,r=1e12,mid;
33     while(r-l>0.0001)
34     {
35           mid=(l+r)/2;
36         if(check(mid))
37          r=mid;
38         else
39          l=mid;
40     }
41     printf("%f
",mid);
42     return 0;
43 }
D. Volatile Kite
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a convex polygon P with n distinct vertices p1, p2, ..., pn. Vertex pi has coordinates (xi, yi) in the 2D plane. These vertices are listed in clockwise order.

You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions.

Find the maximum value of D such that no matter how you move the vertices, the polygon does not intersect itself and stays convex.

Input

The first line has one integer n (4 ≤ n ≤ 1 000) — the number of vertices.

The next n lines contain the coordinates of the vertices. Line i contains two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th vertex. These points are guaranteed to be given in clockwise order, and will form a strictly convex polygon (in particular, no three consecutive points lie on the same straight line).

Output

Print one real number D, which is the maximum real number such that no matter how you move the vertices, the polygon stays convex.

Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .

Examples
Input
4
0 0
0 1
1 1
1 0
Output
0.3535533906
Input
6
5 0
10 0
12 -4
10 -8
5 -8
3 -4
Output
1.0000000000
Note

Here is a picture of the first sample

Here is an example of making the polygon non-convex.

This is not an optimal solution, since the maximum distance we moved one point is  ≈ 0.4242640687, whereas we can make it non-convex by only moving each point a distance of at most  ≈ 0.3535533906.

题意:给你n个点的坐标 求一个最大的d 使得任意的点向任意方向移动距离d都能保持图形为凸多边形。

题解:对于移动某一个点 是否为凸只与相邻的两个点有关 若相邻的两个点不移动则d 为当前点到 相邻两点形成的直线的距离。若相邻点移动 则d=d/2 才能保证凸多边形。所以遍历所有相邻的三个点ans=min(ans,d/2);

  1 #include<bits/stdc++.h>
  2 #define ll __int64
  3 #define mst(ss,b) memset((ss),(b),sizeof(ss))
  4 #define maxn 0x3f3f3f3f
  5 using namespace std;
  6 struct point
  7 {
  8     double x,y;
  9     point(double x=0,double y=0):x(x),y(y) {}
 10 };
 11 typedef point vec;
 12 const double eps=1e-8;
 13 const double pi=acos(-1.0);
 14 bool cmp(point a,point b)
 15 {
 16     if(fabs(a.x-b.x)<=eps) return a.y<b.y;
 17     return a.x<b.x;
 18 }
 19 vec operator -(point a,point b)
 20 {
 21     return vec(a.x-b.x,a.y-b.y);
 22 }
 23 vec operator +(point a,point b)
 24 {
 25     return vec(a.x+b.x,a.y+b.y);
 26 }
 27 vec operator *(point a,double t)
 28 {
 29     return vec(a.x*t,a.y*t);
 30 }
 31 vec operator /(point a,double t)
 32 {
 33     return vec(a.x/t,a.y/t);
 34 }
 35 bool operator < (const point &a,const point &b)
 36 {
 37     return a.y<b.y || (fabs(a.y-b.y)<=eps && a.x<b.x);
 38 }
 39 bool operator == (const point &a,const point &b)
 40 {
 41     if(fabs(a.x-b.x)<=eps && fabs(a.y-b.y)<=eps)
 42         return true;
 43     return false;
 44 }
 45 int dcmp(double x)
 46 {
 47     if(fabs(x)<=eps) return 0;
 48     return x<0?-1:1;
 49 }
 50 double cross(vec a,vec b)  ///叉积
 51 {
 52     return a.x*b.y-a.y*b.x;
 53 }
 54 double dot(vec a,vec b)  ///点积
 55 {
 56     return a.x*b.x+a.y*b.y;
 57 }
 58 double lentgh(vec a) ///向量长度
 59 {
 60     return sqrt(dot(a,a));
 61 }
 62 double distancetoseg(point p,point a,point b)
 63 {
 64     if(a==b) return lentgh(p-a);
 65     vec v1=b-a;
 66     vec v2=p-a;
 67     vec v3=p-b;
 68     if(dcmp(dot(v1,v2))<0)
 69         return lentgh(v2);
 70     else if(dcmp(dot(v1,v3))>0)
 71         return lentgh(v3);
 72     else
 73         return fabs(cross(v1,v2))/lentgh(v1);
 74     /*点到线段的距离*/
 75 }
 76 int main()
 77 {
 78     int n;
 79     double xx[1005],yy[1005];
 80     scanf("%d",&n);
 81     for(int i=1; i<=n; i++)
 82         scanf("%lf %lf",&xx[i],&yy[i]);
 83     double d=1e12;
 84     vec q,w,e;
 85     for(int i=1; i<=n-2; i++)
 86     {
 87         q.x=xx[i];
 88         q.y=yy[i];
 89         w.x=xx[i+1];
 90         w.y=yy[i+1];
 91         e.x=xx[i+2];
 92         e.y=yy[i+2];
 93         d=min(d,distancetoseg(w,q,e)/2.0);
 94     }
 95     q.x=xx[n-1];
 96     q.y=yy[n-1];
 97     w.x=xx[n];
 98     w.y=yy[n];
 99     e.x=xx[1];
100     e.y=yy[1];
101     d=min(d,distancetoseg(w,q,e)/2.0);
102     q.x=xx[n];
103     q.y=yy[n];
104     w.x=xx[1];
105     w.y=yy[1];
106     e.x=xx[2];
107     e.y=yy[2];
108     d=min(d,distancetoseg(w,q,e)/2.0);
109     printf("%f
",d);
110     return 0;
111 }
原文地址:https://www.cnblogs.com/hsd-/p/6724782.html