A的万般无奈。。。后来跑了大牛的这份代码发现,

题意是求一个序列与给定的两个序列有t个不同。

只要保证。。。对应位置就行了。。

所以处理起来非常方便。。。。。。。。。。。。。。

可是没有感觉是对应位置啊瞎几把想了一堆。后来真的是。

再后来?

我觉得非常好的就是又多了那么点见识。。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. typedef unsigned long long ULL;
  5. const double eps=1e-5;
  6. const double pi=acos(-1.0);
  7. const int mod=1e9+7;
  8. const int INF=0x3f3f3f3f;
  9. const int N=1e5+7;
  10. bool status[N];
  11. char Generate(char a,char b)
  12. {
  13. char tmp;
  14. for(int i=0;i<26;i++)
  15. {
  16. tmp='a'+i;
  17. if(tmp!=a&&tmp!=b){
  18. return tmp;
  19. }
  20. }
  21. }
  22. int cout_dif(string a,string b,int len)
  23. {
  24. int res=0;
  25. for(int i=0;i<len;i++){
  26. if(a[i]!=b[i])
  27. res++;
  28. }
  29. return res;
  30. }
  31. int main()
  32. {
  33. int n,t,dif=0;
  34. string a,b,c;
  35. cin>>n>>t;
  36. cin>>a>>b;
  37. c=string(n,'a');
  38. vector<int>pos;
  39. memset(status,0,sizeof(status));
  40. for(int i=0;i<n;i++){
  41. if(a[i]!=b[i]) // 统计给定两串的不同字符数为x。【这样特么就能统计???】
  42. dif++;
  43. else
  44. status[i]=1; //标记共同的
  45. }
  46. if(t==dif){
  47. for(int i=0;i<n;i++){
  48. if(status[i]){ //如果是共同的取好
  49. c[i]=a[i];
  50. }
  51. else //不同直接取个更加不同的
  52. c[i]=Generate(a[i],b[i]);
  53. }
  54. }
  55. else if(t>dif){
  56. int cnt=0; //作为标记掉,用来考虑相同里面的t-dif那部分。
  57. for(int i=0;i<n;i++)
  58. {
  59. if(status[i]){
  60. if(cnt<(t-dif))
  61. {
  62. c[i]=Generate(a[i],b[i]);
  63. cnt++;
  64. }
  65. else
  66. c[i]=a[i];
  67. }
  68. else{ //还是要把不同个取个更加不同的
  69. c[i]=Generate(a[i],b[i]);
  70. }
  71. }
  72. }
  73. else //保持相同部分不变,另挑(x-t)个原不同位置,使之与a串相同//同理,b串。
  74. {
  75. int cnt1=0,cnt2=0;
  76. for(int i=0;i<n;i++){
  77. if(status[i])
  78. c[i]=a[i];
  79. else{
  80. if(cnt1<(dif-t)){
  81. c[i]=a[i];
  82. cnt1++;
  83. }
  84. else if(cnt2<(dif-t)){
  85. c[i]=b[i];
  86. cnt2++;
  87. }
  88. else
  89. c[i]=Generate(a[i],b[i]);
  90. }
  91. }
  92. }
  93. if(cout_dif(a,c,n)==t&&cout_dif(b,c,n)==t)
  94. cout<<c<<endl;
  95. else
  96. cout<<"-1"<<endl;
  97. return 0;
  98. }

Codeforces Round #324 (Div. 2)C. Marina and Vasya的更多相关文章

  1. Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心

    C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...

  2. Codeforces Round #324 (Div. 2)C. Marina and Vasya set

                                                          C. Marina and Vasya   Marina loves strings of ...

  3. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  4. Codeforces Round #324 (Div. 2)

    CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...

  5. Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理

    原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...

  6. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  7. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  8. Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想

    D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  9. Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

    B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...

随机推荐

  1. c程序设计语言第一章3

    字符数组是C语言中最常用的数组类型.下面我们通过编写一个程序,来说明字符数组以反操作字符数组的函数的用法.该程序读入一组文本行,并把最长的文水行打印出来.该算法的基本框架非常简单: while (还有 ...

  2. HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. Objective C运行时(runtime)技术总结,好强大的runtime

    前言:          Objective C的runtime技术功能非常强大,能够在运行时获取并修改类的各种信息,包括获取方法列表.属性列表.变量列表,修改方法.属性,增加方法,属性等等,本文对相 ...

  4. JAVA的WebService规范JAX-WS

    JAX-WS的服务端.客户端双方传输数据使用的SOAP消息格式封装数据. 一.下载apache-cxf-3.1.4.zip. 二.编写服务端 1.编写一个Web Service用来传输参数的类 pac ...

  5. Entity Framework 6 Code First系列1: 实体类1:1配置

    从4.1版本开始,EF开始支持Code First模式,值得注意的是Code First不是和DataBase First或Model First平级的概念,而是和EDM平级的概念.使用Code Fi ...

  6. vmware 自动挂起

    用VMware跑虚拟机,经常会出现客户操作系统自己挂起的现象,怀疑是主机自己休眠的设置.设置之后,无效. 后来才发现不是主机休眠设置,还是应该设置客户操作系统中的休眠设置. 在客户机,控制面板  电源 ...

  7. SignatureDoesNotMatch REST接口 在任何时间、任何地点、任何互联网设备上 在Header中包含签名

    PutObject_关于Object操作_API 参考_对象存储 OSS-阿里云 https://help.aliyun.com/document_detail/31978.html OSS API ...

  8. JVM学习资料收集

    JVM实用参数(一)JVM类型以及编译器模式 http://ifeve.com/useful-jvm-flags-part-1-jvm-types-and-compiler-modes-2/ JVM实 ...

  9. css3的渐变效果

    1.css3 渐变的属性 例子: #grad { background: -webkit-linear-gradient(red, blue); /* Safari 5.1 - 6.0 */ back ...

  10. YTU 2392: 求各位数字之和

    2392: 求各位数字之和 时间限制: 1 Sec  内存限制: 128 MB 提交: 1253  解决: 292 题目描述 编写一个程序,计算任意输入的正整数的各位数字之和.(输入的位数不要超过10 ...