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”数量的最大值输出

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
int main()
{
char a[];
scanf("%s",a);
int len=strlen(a);
int ans=;
for(int i=; i<len-; i++)
{
if(a[i]=='V'&&a[i+]=='K')
ans++;
}
for(int i=; i<len; i++)
{
int exm=;
char ww=a[i];
a[i]='V';
for(int j=; j<len-; j++)
{
if(a[j]=='V'&&a[j+]=='K')
exm++;
}
ans=max(ans,exm);
a[i]=ww;
}
for(int i=; i<len; i++)
{
int exm=;
char ww=a[i];
a[i]='K';
for(int j=; j<len-; j++)
{
if(a[j]=='V'&&a[j+]=='K')
exm++;
}
ans=max(ans,exm);
a[i]=ww;
}
printf("%d\n",ans);
return ;
}
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

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
int main()
{
char a[],b[];
scanf("%s %s",a,b);
int len=strlen(a);
for(int i=;i<len;i++)
{
if(b[i]>a[i])
{
printf("-1\n");
return ;
}
}
printf("%s\n",b);
return ;
}
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;

 #include<bits/stdc++.h>
#define ll __int64
using namespace std;
ll n,p;
ll a[],b[];
bool check(double x)
{
double sum=;
for(int i=;i<=n;i++)
{
if(a[i]*x-b[i]>=0.00000001)
sum+=(a[i]*x-b[i]);
}
if(sum-x*p>=0.000000001)
return true;
else
return false;
}
int main()
{
ll zong=;
scanf("%I64d %I64d",&n,&p);
for(int i=;i<=n;i++){
scanf("%I64d %I64d",&a[i],&b[i]);
zong+=a[i];
}
if(zong<=p)
{
printf("-1\n");
return ;
}
double l=,r=1e12,mid;
while(r-l>0.0001)
{
mid=(l+r)/;
if(check(mid))
r=mid;
else
l=mid;
}
printf("%f\n",mid);
return ;
}
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);

 #include<bits/stdc++.h>
#define ll __int64
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
using namespace std;
struct point
{
double x,y;
point(double x=,double y=):x(x),y(y) {}
};
typedef point vec;
const double eps=1e-;
const double pi=acos(-1.0);
bool cmp(point a,point b)
{
if(fabs(a.x-b.x)<=eps) return a.y<b.y;
return a.x<b.x;
}
vec operator -(point a,point b)
{
return vec(a.x-b.x,a.y-b.y);
}
vec operator +(point a,point b)
{
return vec(a.x+b.x,a.y+b.y);
}
vec operator *(point a,double t)
{
return vec(a.x*t,a.y*t);
}
vec operator /(point a,double t)
{
return vec(a.x/t,a.y/t);
}
bool operator < (const point &a,const point &b)
{
return a.y<b.y || (fabs(a.y-b.y)<=eps && a.x<b.x);
}
bool operator == (const point &a,const point &b)
{
if(fabs(a.x-b.x)<=eps && fabs(a.y-b.y)<=eps)
return true;
return false;
}
int dcmp(double x)
{
if(fabs(x)<=eps) return ;
return x<?-:;
}
double cross(vec a,vec b) ///叉积
{
return a.x*b.y-a.y*b.x;
}
double dot(vec a,vec b) ///点积
{
return a.x*b.x+a.y*b.y;
}
double lentgh(vec a) ///向量长度
{
return sqrt(dot(a,a));
}
double distancetoseg(point p,point a,point b)
{
if(a==b) return lentgh(p-a);
vec v1=b-a;
vec v2=p-a;
vec v3=p-b;
if(dcmp(dot(v1,v2))<)
return lentgh(v2);
else if(dcmp(dot(v1,v3))>)
return lentgh(v3);
else
return fabs(cross(v1,v2))/lentgh(v1);
/*点到线段的距离*/
}
int main()
{
int n;
double xx[],yy[];
scanf("%d",&n);
for(int i=; i<=n; i++)
scanf("%lf %lf",&xx[i],&yy[i]);
double d=1e12;
vec q,w,e;
for(int i=; i<=n-; i++)
{
q.x=xx[i];
q.y=yy[i];
w.x=xx[i+];
w.y=yy[i+];
e.x=xx[i+];
e.y=yy[i+];
d=min(d,distancetoseg(w,q,e)/2.0);
}
q.x=xx[n-];
q.y=yy[n-];
w.x=xx[n];
w.y=yy[n];
e.x=xx[];
e.y=yy[];
d=min(d,distancetoseg(w,q,e)/2.0);
q.x=xx[n];
q.y=yy[n];
w.x=xx[];
w.y=yy[];
e.x=xx[];
e.y=yy[];
d=min(d,distancetoseg(w,q,e)/2.0);
printf("%f\n",d);
return ;
}

Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何的更多相关文章

  1. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)

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

  2. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) D. Volatile Kite

    地址:http://codeforces.com/contest/801/problem/D 题目: D. Volatile Kite time limit per test 2 seconds me ...

  3. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) C Voltage Keepsake

    地址:http://codeforces.com/contest/801/problem/C 题目: C. Voltage Keepsake time limit per test 2 seconds ...

  4. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】

    A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...

  5. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)

    A 每次可以换一个或不换,暴力枚举位置即可 B 模拟 C 二分答案.. 边界可以优化r=totb/(tota-p),二分可以直接(r-l>=EPS,EPS不要太小,合适就好),也可以直接限定二分 ...

  6. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  7. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心

    C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题

    B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...

  9. 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

    我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...

随机推荐

  1. 面向对象编程(OOP)思想小结

    Concepts 类(class):对我们要解决问题的抽象,比如建造房子的蓝图:但实现机制上来讲,类是根据蓝图构建而成的,存储在内存中的,用来表示对象的数据. 对象(object):根据类构建的实体, ...

  2. Valgrind 简单用法

    有时需要给自己写的小程序做个简单的 benchmark,查看内存使用情况和运行时间.这时可以试试 valgrind. Ubuntu 下安装很简单: sudo apt-get update sudo a ...

  3. Codeforces Round #613 Div.1 D.Kingdom and its Cities 贪心+虚树

    题目链接:http://codeforces.com/contest/613/problem/D 题意概述: 给出一棵树,每次询问一些点,计算最少删除几个点可以让询问的点两两不连通,无解输出-1.保证 ...

  4. ORA-01747

    java.sql.SQLException: ORA-01747: user.table.column, table.column 或列说明 语法中多了逗号 或者字段使用关键字

  5. TDGA-需求分析

    李青:绝对的技术控,团队中扮演“猪”的角色,勤干肯干,是整个团队的主心骨,课上紧跟老师的步伐,下课谨遵老师的指令,课堂效率高,他的编程格言“没有编不出来的程序,只有解决不了的bug”. 胡金辉:半两油 ...

  6. 下载与安装APache Cordova

    最近老师留了写网页版或手机版程序,但先前没有好好听javaweb,而今年又没选Android移动应用开发.所以去图书馆借了一本书是关于HTML5+CSS3+jQueryMobile的. 这几天配置了打 ...

  7. HDU 5273 Dylans loves sequence 暴力递推

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5273 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  8. Java throw try catch

    public class Runtest { public static void main(String[] args) { // TODO Auto-generated method stub T ...

  9. QHash和QMultiHash使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QHash和QMultiHash使用     本文地址:http://techieliang. ...

  10. 使用selenium遍历frame中的表单信息 ;

    遍历frame中的表单 : package webDriverPro; import java.util.List; import java.util.regex.Matcher; import ja ...