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. 数据库sql优化总结之1-百万级数据库优化方案+案例分析

    项目背景 有三张百万级数据表 知识点表(ex_subject_point)9,316条数据 试题表(ex_question_junior)2,159,519条数据 有45个字段 知识点试题关系表(ex ...

  2. A Bug's Life(加权并查集)

    Description Background  Professor Hopper is researching the sexual behavior of a rare species of bug ...

  3. 王者荣耀交流协会 -- 第4次Scrum会议

    Scrum master : 王磊 要求1 : 工作照片 照片由高远博同学拍摄 ,王露芝同学(外援)没有参加本次会议. 要求2 : 时间跨度:2017年10月16日 18:00 - 18:44 共计4 ...

  4. FivePlus——团队展示

    光耀101  <光耀101>是福州大学数计学院计算机专业推出的中国首部程序猿脱发养成节目.由张栋担任发起人,刘晨瑶.畅畅担任导师.  该节目召集了你猜多少位选手,通过任务.训练.考核,让选 ...

  5. 软工 · 第十一次作业 - Alpha 事后诸葛亮(团队)

    软工 · 第十一次作业 - Alpha 事后诸葛亮(团队) 组长本次作业链接 现代软件工程 项目Postmortem 设想和目标 1.我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场 ...

  6. 如何通过JAVA让DB2调用操作系统命令

    引言:我们在工作中常用操作系统命令和DB2命令对数据库做数据的导入.导出等操作,但是DB2不支持复合SQL 语句调用操作系统命令,因此我们需要利用 UDF 来执行SQL 中不可用的操作(例如:执行一些 ...

  7. WPF和Expression Blend开发实例:Loading动画

    今天来点实际的,项目中可以真实使用的,一个Loading的动画,最后封装成一个控件,可以直接使用在项目中,先上图: 整个设计比较简单,就是在界面上画18个Path,然后通过动画改变OpacityMas ...

  8. Mac下Java JNI 调C

    简介 JNI的实现步骤如下: 编写带有native声明的方法的Java类 使用javac命令编译编写的Java类 使用java -jni className 来生成后缀名为.h的头文件 使用其他语言( ...

  9. Android Studio -导入项目 gradle处理

    如果导入 android studio 项目, 那么一定要注意 需要合适的gradle版本,具体方法为: 首先导入步骤: 打开android studio ==> File ==> New ...

  10. shit Rap & mock api

    shit Rap & mock api https://thx.github.io/RAP/study.html https://github.com/thx/RAP/wiki/quick_g ...