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. 《Node.js核心技术教程》学习笔记

    <Node.js核心技术教程>TOC \o "1-3" \h \z \u 1.章模块化编程 2019.2.19 13:30' PAGEREF _101 \h 1 08D ...

  2. phpcms v9手机站不支持组图($pictureurls)的修改

    phpcms v9自带的手机门户网站,有时候我们需要用到组图功能$pictureurls,我在做的时候发现,如果$pictureurls中只有一张图片会正常显示,但是如果有两张或两张以上的图片的时候, ...

  3. mac 安装配置使用nexus3.x

    一.nexus安装 前置条件 :已经安装了JDK 1:下载nexus(http://www.sonatype.com/download-oss-sonatype) 最新版本3.0,下载目录为/User ...

  4. 【数位dp】Enigma

    http://codeforces.com/gym/101889 E 与一般数位dp不同,保存的是能否满足条件,而非记录方案数 代码: #include <iostream> #inclu ...

  5. 团队Alpha冲刺(十)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  6. C#高级编程 (第六版) 学习 第七章:委托和事件

    第七章 委托和事件 回调(callback)函数是Windows编程的一个重要方面,实际上是方法调用的指针,也称为函数指针. .Net以委托的形式实现了函数指针的概念,.Net的委托是类型安全的. 委 ...

  7. WPF浏览器应用程序与JS的互调用(不用WebBrowser)

    首先说些题外话,很久没有写博客了,空间里面的大部分文章还是11年写的.那时候刚毕业就来到这家公司,参与到一个Asp.net MVC的项目开发中,这个项目是一个全新的项目,连项目开发框架都没有,亏得领导 ...

  8. MySQL 忘记root密码怎么办

    前言:记住如果忘记root密码,在启动MySQL的时候,跳过查询授权表就ok了. 对于RedHat 6 而言 (1)启动mysqld 进程时,为其使用:--skip-grant-tables --sk ...

  9. 个人项目----词频统计WEB(部分功能)

    需求分析 1.使用web上传txt文件,对上传的txt进行词频统计. 2.将统计后的结果输出到web页面,力求界面优美. 3.在界面上展示所给url的文章词频统计,力求界面优美. 3.将每个单词同四. ...

  10. [CB] Windows10为什么质量变差 bug越来越多

    在 Windows 10 发布之后,微软转向了软件即服务模式,每半年释出一个新版本,通过增加更新频率将新的特性不断推送给用户. 在以前,微软产品发布周期是两到三年,其开发流程分成多个阶段:设计和策划. ...