Problem Statement

A string S is a subsequence of a string T if we can obtain S from T by erasing some (possibly all or none) of its characters. For example, “000” is a subsequence of “01010”. The longest common subsequence (LCS) of two strings A and B is a string C that is a subsequence of each of them and has the largest length among all strings with this property. Let f(A,B) be the length of the LCS of strings A and B. For example, we have f(“101”, “111000”) = 2, f(“101”, “110011”) = 3, and f(“00”, “1111”) = 0. You are given three small positive integers ab, bc, and ca. Please find three strings A, B, C such that:

Each of the strings contains only the characters ‘0’ and ‘1’.

The length of each string is between 1 and 1,000, inclusive.

f(A, B) = ab

f(B, C) = bc

f(C, A) = ca

Return a string formed as follows: A + ” ” + B + ” ” + C. (I.e., the returned string should contain the three strings A, B, C, separated by single spaces.) You may assume that a solution always exist. If there are multiple solutions you may return any of them.

Definition

Class:

ConstructLCS

Method:

construct

Parameters:

int, int, int

Returns:

string

Method signature:

string construct(int ab, int bc, int ca)

(be sure your method is public)

Limits

Time limit (s):

2.000

Memory limit (MB):

256

Stack limit (MB):

256

Constraints

ab will be between 1 and 50, inclusive.

bc will be between 1 and 50, inclusive.

ca will be between 1 and 50, inclusive.

Examples

0)

3

4

2

Returns: “101 1010101 1111”

The returned string corresponds to the following solution:

A = “1111”

B = “101”

C = “1010101”

We can easily verify that the only LCS of A and B is “11”, the only LCS of B and C is “101”, and the only LCS of C and A is “1111”.

1)

7

4

4

Returns: “10101010 1010101 1011”

There are other solutions like: A = “1110000”, B = “1110000”, C = “0000”.

2)

8

7

8

Returns: “110101001011 010101101 10101010”

3)

8

6

7

Returns: “110101010 10101010 1111010”

4)

15

17

19

Returns: “000100101101111011000 11110111010011101010 100100001010101001010101000011111”

5)

50

50

50

Returns:

“11111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111”

【题目链接】:

【题意】



让你构造出3个只包含数字0和1的字符串a,b,c;

给你3个数字ab,bc,ca

表示所要求的a和b的LCS长度为ab,b和C的LCS长度为….

【题解】



找出最大的两个数字;

它所代表的两条边,必然有同时连向同一个点x;

“a、b、c分别代表3个点”

设两条边的边权从大到小分别为a1,a2

则令x+=a1个’1’;

x+=a2个’0’;

然后令a1的另一端的点所代表的字符串为a1个’1’

同时a2的另一端的点所代表的字符串为a2个’0’

然后a3的话,可以不断的在只含‘0’的那个字符串的开头一直把‘0’换成1;直到满足a3为止.



【Number Of WA】



0



【反思】



想得太慢了,没来得及交上去QAQ;

狂跌100+rating;

下次要打div2了:(



【完整代码】

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define lson l,m,rt<<1
  4. #define rson m+1,r,rt<<1|1
  5. #define LL long long
  6. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  7. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  8. #define mp make_pair
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define ms(x,y) memset(x,y,sizeof x)
  13. #define Open() freopen("F:\\rush.txt","r",stdin)
  14. #define Close() ios::sync_with_stdio(0)
  15. typedef pair<int,int> pii;
  16. typedef pair<LL,LL> pll;
  17. const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
  18. const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
  19. const double pi = acos(-1.0);
  20. const int N = 110;
  21. //head
  22. struct abc{
  23. int idx1,idx2,num;
  24. };
  25. abc a[4];
  26. int b[4];
  27. vector <pii> g[4];
  28. string s[4];
  29. class ConstructLCS
  30. {
  31. public:
  32. string construct(int ab, int bc, int ca)
  33. {
  34. rep1(i,1,3) s[i]="";
  35. a[1].idx1 = 1,a[1].idx2 = 2,a[1].num = ab;
  36. a[2].idx1 = 2,a[2].idx2 = 3,a[2].num = bc;
  37. a[3].idx1 = 1,a[3].idx2 = 3,a[3].num = ca;
  38. sort(a+1,a+1+3,[&] ( abc a ,abc b) {return a.num > b.num;});
  39. int ma = 0;
  40. rep1(i,1,2){
  41. int x = a[i].idx1,y = a[i].idx2;
  42. b[a[i].idx1]++,b[a[i].idx2]++;
  43. ma = max(ma,a[i].num);
  44. g[x].pb(mp(y,a[i].num)),g[y].pb(mp(x,a[i].num));
  45. }
  46. int mid = 1;
  47. rep1(i,1,3){
  48. if (b[i]>1){
  49. mid = i;
  50. rep1(j,1,max(g[i][0].se,g[i][1].se))
  51. s[i]+='1';
  52. rep1(j,1,min(g[i][0].se,g[i][1].se))
  53. s[i]+='0';
  54. break;
  55. }
  56. }
  57. int bigger = 0,smaller = 0;
  58. rep1(i,1,3){
  59. if (mid==i) continue;
  60. if (bigger==0 && ma==g[i][0].se){
  61. rep1(j,1,ma)
  62. s[i]+='1';
  63. bigger = i;
  64. }
  65. else{
  66. rep1(j,1,g[i][0].se)
  67. s[i]+='0';
  68. smaller = i;
  69. }
  70. }
  71. int t = a[3].num;
  72. int now = 0;
  73. while (t--){
  74. s[smaller][now++] = '1';
  75. }
  76. return s[1] + ' ' + s[2] + ' ' + s[3];
  77. }
  78. };

【SRM 716 DIV 1 A】 ConstructLCS的更多相关文章

  1. 【TC SRM 718 DIV 2 B】Reconstruct Graph

    [Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...

  2. 【TC SRM 718 DIV 2 A】RelativeHeights

    [Link]: [Description] 给你n个数字组成原数列; 然后,让你生成n个新的数列a 其中第i个数列ai为删掉原数列中第i个数字后剩余的数字组成的数列; 然后问你这n个数列组成的排序数组 ...

  3. 【topcoder SRM 702 DIV 2 250】TestTaking

    Problem Statement Recently, Alice had to take a test. The test consisted of a sequence of true/false ...

  4. 【codeforces 434 div 1 A】Did you mean...

    [链接]h在这里写链接 [题意] 让你维护一段序列. 这段序列,不会出现连续3个以上的辅音. (或者一块全是辅音则也可以) (用空格可以断开连续次数); 要求空格最小. [题解] 模拟着,别让它出现连 ...

  5. 【如何使用jQuery】【jQuery弹出框】【jQuery对div进行操作】【jQuery对class,id,type的操作】【jquery选择器】

    1.如何使用jQuery jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设计的宗旨 ...

  6. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  7. 【three.js详解之一】入门篇

    [three.js详解之一]入门篇   开场白 webGL可以让我们在canvas上实现3D效果.而three.js是一款webGL框架,由于其易用性被广泛应用.如果你要学习webGL,抛弃那些复杂的 ...

  8. 【iScroll源码学习04】分离IScroll核心

    前言 最近几天我们前前后后基本将iScroll源码学的七七八八了,文章中未涉及的各位就要自己去看了 1. [iScroll源码学习03]iScroll事件机制与滚动条的实现 2. [iScroll源码 ...

  9. 【maven + hibernate(注解) +spring +springMVC】 使用maven搭建项目

    研究,百度,查资料+好友帮助,使用MyEcplise2015工具,通过maven搭建hibernate+springMVC+spring的项目,数据库采用MySql5.5 不过使用的版本会在项目搭建过 ...

随机推荐

  1. oracle动态磁盘管理

    一.ASM发展: oracle 想做硬件: 收购sum公司的小型机业务 推出一体机Exadata 1.sum服务器 2.磁盘柜(没做存储) 推出asm建库方式配合一体机(自动使用磁盘柜的盘)(抛弃ra ...

  2. 线程与cpu

    A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set of ...

  3. PHP十六个魔术方法

    PHP中把以两个下划线__开头的方法称为魔术方法(Magic methods),这些方法在PHP中充当了举足轻重的作用. 魔术方法包括: __construct(),类的构造函数 __destruct ...

  4. 洛谷P4894 GodFly求解法向量

    如果没有学过向量相关知识请出门右转高中数学必修四~~~ 当然如果你和我一样也是小学生我也不反对 首先说结论:\(\vec{z}=(y1z2-y2z1,z1x2-z2x1,x1y2-x2y1)\) 其实 ...

  5. Edward Frenkel关于几何化朗兰兹纲领的采访

    本文来自:菲尔兹奖座谈会 博客 Edward Frenkel教授的主要研究方向是数学与量子物理中的对称.他现在在做的许多问题都与朗兰兹纲领有关.他现在是加州大学伯克利分校的数学教授. 在今年的菲尔兹奖 ...

  6. 精品JS代码收藏大全

    1. oncontextmenu="window.event.returnvalue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu ...

  7. spring boot启动STS 运行报错 java.lang.NoClassDefFoundError: ch/qos/logback/classic/LoggerContext

    spring boot启动STS 运行报错 java.lang.NoClassDefFoundError: ch/qos/logback/classic/LoggerContext 学习了: http ...

  8. 在AutoLyout中动态获得cell的高度 和 autoLyout中的小随笔

    autoLyout中动态获得cell的高度和autoLyout小总结 一.在autoLyout中通过动态的方式来获取cell 的方式呢? 1.       在布局时候要有对于cell中contentV ...

  9. OC中的@的作用研究

    OC中的@字符用的频率很的高,其主要作用是为了差别于其它语言的keyword和语法 以下我们来研究一下其应用 1.声明类,协议,延展,权限,属性等 @interface声明类 @protocol声明协 ...

  10. C++ double转string类型以及MFC控件简单使用方法

    这两天项目须要,測试c++库里面内容.生成jar再给Android调用.我没有学过C++,如今開始记录C++简单使用方法.測试时候一般都是使用mfc程序来測试.要输入值.显示结果吗.我用的编译环境vs ...