”All you need is love. All you need is love.
All you need is love, love… love is all you need.”
The Beatles

There was invented a new powerfull gadget by the International Beautifull Machines corporation called the love machine! Given a string made of binary digits, the love machine answers if it’s made only of love, that is, if all you need is love to build that string. The definition of love for the love machine is another string of binary digits, given by a human operator. Let’s say we have a string L which represents “love” and we give a string S for the love machine. We say that all you need is love to build S, if we can repeatly subtract L from S until we reach L. The subtraction defined here is the same arithmetic subtra
    If S = L then S is obvious made of love.
    Let’s see an example. Supose S = “11011” and L = “11”. If we reapetly subtract L from S, we get: 11011, 11000, 10101, 10010, 1111, 1100, 1001, 110, 11. So, given this L, all you need is love to build S. Because of some limitations of the love machine, there can be no string with leading zeroes. That is, “0010101”, “01110101”, “011111”, etc. are invalid strings. Strings which have only one digit are also invalid (it’s another limitation).
    Your task in this problem is: given two valid binary strings, S1 and S2, find if it’s possible to have a valid string L such that both S1 and S2 can be made only of L (i.e. given two valid strings S1 and S2, find if there exists at least one valid string L such as both S1 and S2 are made only of L). For instance, for S1 = 11011 and S2 = 11000, we can have L = 11 such that S1 and S2 are both made only of L (as we can see in the example above).
Input
The first line of input is a positive integer N < 10000 which stands for the number of teste cases. Then, 2 ∗ N lines will follow. Each pair of lines consists in one teste case. Each line of the pair stands for each string (S1 and S2) to be entered as an input for the love machine. No string will have more than 30 characters. You can assume that all strings in the input will be valid acording to the rules above.
Output
For each string pair, you must print one of the following messages:
Pair #p: All you need is love!
Pair #p: Love is not all you need!
    Where p stands for the pair number (starting from 1). You should print the first message if there exists at least one valid string L such as both S1 and S2 can be made only of L. Otherwise, print the second line.
Sample Input
5
11011
11000
11011
11001
111111
100
1000000000
110
1010
100
Sample Output
Pair #1: All you need is love!
Pair #2: Love is not all you need!
Pair #3: Love is not all you need!
Pair #4: All you need is love!
Pair #5: All you need is love!

问题链接:UVA10193 All You Need Is Love
问题简述:(略)
问题分析
    进制转换和GCD计算问题,不多解释。
    程序中使用了函数__gcd(),就不用自己写计算GCD的函数了。写一个适用于不同进制转换字符为整数的函数,相对来说会比较快一些。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10193 All You Need Is Love */#include <bits/stdc++.h>using namespace std;const int N = 30;
char s[N + 1];int myatoi(char s[], int base)
{int ans = 0;for(int i = 0; s[i]; i++) {ans *= base;ans += s[i] - '0';}return ans;
}int main()
{int t, s1, s2;scanf("%d", &t);for(int k = 1; k <= t; k++) {scanf("%s", s);s1 = myatoi(s, 2);scanf("%s", s);s2 = myatoi(s, 2);if(__gcd(s1, s2) > 1) printf("Pair #%d: All you need is love!\n", k);else printf("Pair #%d: Love is not all you need!\n", k);}return 0;
}

UVA10193 All You Need Is Love【进制+GCD】相关推荐

  1. java 16进制与图片互转

    十六进制转成图片 /*** 十六进制转成图片* @author Administrator**/public static void saveToImgFile(String src,String o ...

  2. LeetCode简单题之K 进制表示下的各位数字总和

    题目 给你一个整数 n(10 进制)和一个基数 k ,请你将 n 从 10 进制表示转换为 k 进制表示,计算并返回转换后各位数字的 总和 . 转换后,各位数字应当视作是 10 进制数字,且它们的总和 ...

  3. LeetCode简单题之七进制数

    题目 给定一个整数 num,将其转化为 7 进制,并以字符串形式输出. 示例 1: 输入: num = 100 输出: "202" 示例 2: 输入: num = -7 输出: & ...

  4. Java IDEA Debug进制二维数组

    1.Debug模式 1.1 什么是Debug模式 是供程序员使用的程序调试工具,它可以用于查看程序的执行流程,也可以用于追踪程序执行过程来调试程序. 1.2 Debug介绍与操作流程 如何加断点 选择 ...

  5. python 16进制转10进制, 8进制转10进制, 2进制转10进制的方法

    python 16进制转10 进制, 8进制转10进制, 2进制转10进制 可以使用系统自带的 int 方法 具体如下: value = "0x1388" result = int ...

  6. Java中byte与16进制字符串的互相转换

    https://www.cnblogs.com/qinwangchen/p/5418028.html * Convert byte[] to hex string.这里我们可以将byte转换成int, ...

  7. 【Luogu】P1013进制位(搜索)

    题目链接在这里 这题和虫食算比较类似.做完这道题可以去做虫食算.都是搜索一类的题. 这样 我们分析题目可以发现进制只可能是字母的个数,也就是n-1.为什么? 因为题目要求完整的加法表才算数.如果进制低 ...

  8. -变量,进制,数据类型,标识符

    ###02.01_Java语言基础(常量的概述和使用)(掌握) * A:什么是常量 * 在程序执行的过程中其值不可以发生改变 * B:Java中常量的分类 * 字面值常量 * 自定义常量(面向对象部分 ...

  9. python中不同进制的整数之间可以直接运算_Python 进制转换、位运算

    一.进制转换 编程用十进制,十进制转换为二进制.八进制.十六进制 In [135]: bin(23) Out[135]: '0b10111' In [136]: oct(23) Out[136]: ' ...

最新文章

  1. Introduction to pinatrace annotate version 2: a look into latches again
  2. AngularJS+Satellizer+Node.js+MongoDB-Instagram-20
  3. css中使用id和class 的不同
  4. 笔记-项目范围管理-需求工程-需求管理
  5. 如何用Seaborn描绘线图,分面网格关联图,密度图,连接图,热力图,线性回归图,分面网格绘图
  6. 魅族android n内测报名,不再万年Android 5.0! Flyme安卓N内测招募开启
  7. jdbc获取mysql第二行表信息_【奇技淫巧】MySQL另类方法获取元数据信息
  8. Unity 2D Skeletal Animation
  9. IO子系统的层次结构
  10. HDU 2076 夹角有多大
  11. 点击一下就射击的java代码_Java面向对象(6) —— 射击小游戏
  12. Java数字抽奖游戏核心代码及分析
  13. 使用FreeImage保存彩图,灰度图
  14. Zemax操作38--POP(物理光学传播)的用法
  15. 【精益生产】108页PPT搞懂精益生产价值流分析图(VSM)
  16. iOS9.3描述文件怎么安装
  17. HTTP Live Streaming (HLS) - 概念
  18. 牛客练习赛53 (E 老瞎眼 pk 小鲜肉) 线段树+离线
  19. NYOJ 33 蛇形填数
  20. 【认知觉醒:开启自我改变的原动力】

热门文章

  1. /etc/udev/rules.d/10-usbstorage.rules
  2. centos mysql-5.5.20_mysql-5.5.20+CentOS 6.2 编译安装全过程详解(2)
  3. ArcGIS水文分析实战教程(12)河网分级流程
  4. Grafana全面瓦解
  5. 让C#语言充当自身脚本!——.NET中的动态编译
  6. 数据正则化matlab程序,求助 计量经济模型中用Tikhonov正则化方法参数估计程序修改...
  7. Linux基础命令与进阶
  8. html文本框连接数据库失败,从按钮点击将数据从MySQL数据库加载到HTML文本框
  9. Kafka核心概念及核心机制
  10. Broadcast variabies-广播变量