A. Vicious Keyboard

题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多。

题解:数据范围很小,暴力枚举改变哪个字符,然后check就好。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. string s;
  5. cin>>s;
  6. int ans = 0;
  7. for(int i=0;i<s.size();i++){
  8. if(s[i]=='V'){
  9. s[i]='K';
  10. }else
  11. s[i]='V';
  12. int tmp = 0;
  13. for(int j=0;j<s.size()-1;j++){
  14. if(s[j]=='V'&&s[j+1]=='K')
  15. tmp++;
  16. }
  17. ans=max(ans,tmp);
  18. if(s[i]=='V')
  19. s[i]='K';
  20. else
  21. s[i]='V';
  22. }
  23. int tmp = 0;
  24. for(int j=0;j<s.size()-1;j++){
  25. if(s[j]=='V'&&s[j+1]=='K')
  26. tmp++;
  27. }
  28. ans=max(ans,tmp);
  29. cout<<ans<<endl;
  30. }

B. Valued Keys

题意:定义f(x,y),表示选择字符串中字典序最小的那个字符,然后现在你需要构造一个b,满足f(a,b)=c

题解:如果c[i]>a[i],那么就显然非法,否则b[i]=c[i]即可。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. string a,b,c;
  5. cin>>a>>b;
  6. for(int i=0;i<a.size();i++){
  7. if(b[i]>a[i]){
  8. cout<<"-1"<<endl;
  9. return 0;
  10. }else
  11. c+=b[i];
  12. }
  13. cout<<c<<endl;
  14. }

C. Voltage Keepsake

题意:你有个充电器,每秒钟可以充p的电。然后你有n个装置,每个装置每秒钟增加a[i],一开始有b[i]。请问最多多少秒,可以使得每一个装置都能运作下去。

题解:显然的二分答案,呈现单调性。然后我们贪心的去充电即可。注意二分的姿势应该是枚举二分的次数。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e5+7;
  4. double a[maxn],b[maxn],p;
  5. int n;
  6. bool check(double x){
  7. double las=x*p;
  8. for(int i=0;i<n;i++){
  9. if(b[i]+las<a[i]*x)return false;
  10. if(b[i]>=a[i]*x)continue;
  11. las-=(a[i]*x-b[i]);
  12. }
  13. return true;
  14. }
  15. int main(){
  16. cin>>n>>p;
  17. for(int i=0;i<n;i++)
  18. cin>>a[i]>>b[i];
  19. //cout<<check(2)<<endl;
  20. double l = 0,r = 1e15;
  21. for(int i=0;i<150;i++){
  22. double mid = (l+r)/2.0;
  23. if(check(mid))l=mid;
  24. else r=mid;
  25. //cout<<l<<" "<<r<<endl;
  26. }
  27. if(l>=1e14){
  28. cout<<"-1"<<endl;
  29. }else{
  30. printf("%.10f\n",l);
  31. }
  32. }

D. Volatile Kite

题意:问你凸包上每个点最多移动多少,可以使得这个凸包仍然是一个凸包。

题解:答案就是p[i]这个点,离p[i-1],p[i+1]点的距离,最小值除以2。至于答案为什么这个,我就猜了一发结论,然后交一发就过了。。。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e3+6;
  4. struct node{
  5. double x,y;
  6. }p[maxn];
  7. int n;
  8. double dis(node A,node B){
  9. return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
  10. }
  11. double area(node A,node B,node C){
  12. double l1 = dis(A,B);
  13. double l2 = dis(B,C);
  14. double l3 = dis(A,C);
  15. double p = (l1+l2+l3)/2.0;
  16. return sqrt(p*(p-l1)*(p-l2)*(p-l3));
  17. }
  18. int main(){
  19. scanf("%d",&n);
  20. for(int i=0;i<n;i++){
  21. cin>>p[i].x>>p[i].y;
  22. }
  23. double ans = 1e15;
  24. for(int i=0;i<n;i++){
  25. ans = min(ans,area(p[i],p[(i+1)%n],p[(i-1+n)%n])*2/dis(p[(i+1)%n],p[(i-1+n)%n]));
  26. }
  27. printf("%.12f\n",ans/2.0);
  28. //cout<<ans/2<<endl;
  29. }

C. Vulnerable Kerbals

题意:你需要构造一个最长的序列,满足以下要求:

1.前缀乘积在%m的情况下,应该都不一样。

2.规定的n个数,不能在前缀乘积中出现。

3.序列中的每个数都应该是[0,m)的。

题解:假设gcd(a,m)%gcd(b,m)==0,那么就显然会存在一个k,使得ak%m=b。那么这道题就按照gcd分类,然后用dp求一个最长路,然后再解同余方程,求解每一个k即可。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 2e5+7;
  4. vector<int> P[maxn],E[maxn];
  5. int n,m,vis[maxn],dp[maxn],from[maxn],phi[maxn];
  6. int gcd(int a,int b){
  7. if(b==0)return a;
  8. return gcd(b,a%b);
  9. }
  10. long long qpow(long long a,long long b,long long c){
  11. long long res = 1;
  12. while(b){
  13. if(b&1)res=res*a%c;
  14. a=a*a%c;
  15. b>>=1;
  16. }
  17. return res;
  18. }
  19. void pre(){
  20. for(int i=1;i<maxn;i++){
  21. phi[i]+=i-1;
  22. for(int j=2*i;j<maxn;j+=i){
  23. phi[j]-=phi[i];
  24. }
  25. }
  26. }
  27. int main(){
  28. pre();
  29. scanf("%d%d",&n,&m);
  30. if(m==1){
  31. cout<<"1\n0\n"<<endl;
  32. return 0;
  33. }
  34. for(int i=1;i<=n;i++){
  35. int x;scanf("%d",&x);
  36. vis[x]=1;
  37. }
  38. for(int i=0;i<m;i++){
  39. if(vis[i])continue;
  40. P[gcd(i,m)].push_back(i);
  41. }
  42. int mx = 0;
  43. for(int i=m;i>0;i--){
  44. from[i]=-1;
  45. for(int j=2*i;j<m;j+=i){
  46. if(dp[j]>dp[i]){
  47. dp[i]=dp[j];
  48. from[i]=j;
  49. }
  50. }
  51. dp[i]+=P[i].size();
  52. if(dp[i]>dp[mx]){
  53. mx=i;
  54. }
  55. }
  56. if(vis[0]==0)dp[mx]++;
  57. cout<<dp[mx]<<endl;
  58. int last = 1;
  59. while(mx!=-1){
  60. for(int i=0;i<P[mx].size();i++){
  61. int x = P[mx][i];
  62. int g = gcd(last,x);
  63. g = gcd(g,m);
  64. cout<<(x/g)*qpow((last/g),phi[m/g]-1,m/g)%(m/g)<<" ";
  65. last=x;
  66. }
  67. mx=from[mx];
  68. }
  69. if(vis[0]==0)cout<<"0";
  70. cout<<endl;
  71. }

Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】的更多相关文章

  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)

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

  5. 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 ...

  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. C# 实现UDP打洞通信(一)

    最近研究了一下网络打洞的相关技术,TCP的方式据说可行性不高,各种困难,因此决定采用UDP(UDP是什么就不解释了)的方式. 原理: 我们都知道局域网内的主机想要访问外网的服务器是比较容易的,比如浏览 ...

  2. 编译时bad substitution的解决办法

    由于使用的使用的编译器不同导致, 需要使用shell为 #!/bin/bash 即可.

  3. mysql数据库基于LVM快照的备份

    lvm-snapshot: 基于LVM快照的备份 1.事务日志跟数据文件必须在同一个卷上          2.创建快照卷之前,要请求mysql的全局锁,在快照创建完成之后释放锁          3 ...

  4. POJ 3243 // HDU 2815(改下输出,加个判断)

    A^x = B (mod C) 的模板题,不够要用扩展BSGS (虽然AC,但完全理解不了模板0.0,以后学好数学在来慢慢理解555555) #include <iostream> #in ...

  5. Linux服务器性能评估

    一.影响Linux服务器性能的因素 1. 操作系统级 CPU 内存 磁盘I/O带宽 网络I/O带宽 2. 程序应用级 二.系统性能评估标准 影响性能因素 影响性能因素 评判标准 好 坏 糟糕 CPU ...

  6. 关于报错stale element reference: element is not attached to the page document处理

    1.现象 在执行脚本时,有时候引用一些元素对象会抛出如下异常 org.openqa.selenium.StaleElementReferenceException: stale element ref ...

  7. Android 的网络编程

    android的网络编程分为2种:基于socket的,和基于http协议的. 基于socket的用法 服务器端: 先启动一个服务器端的socket     ServerSocket svr = new ...

  8. 纯 Java 开发 WebService 调用测试工具(wsCaller.jar)

    注:本文来自hacpai.com:Tanken的<纯 Java 开发 WebService 调用测试工具(wsCaller.jar)>的文章 基于 Java 开发的 WebService ...

  9. 用javascript判断当前是安卓平台还是ios平台

    通常判断运行环境都是通过navigator.userAgent if (/android/gi.test(navigator.userAgent)){ // todo : android} if (/ ...

  10. body-parser Node.js(Express) HTTP请求体解析中间件

    body-parser Node.js(Express) HTTP请求体解析中间件 2016年06月08日     781     声明 在HTTP请求中,POST.PUT和PATCH三种请求方法中包 ...