Topic 1151: Bit manipulation exercises

Source: Internet
Author: User

Title Address: http://ac.jobdu.com/problem.php?pid=1151

Topic 1151: Bit manipulation exercises

time limit:1 seconds memory limit:32 trillion special sentence: no submission:1687 resolution:927

Title Description:

Give two nonnegative integers not greater than 65535, and determine whether one of the 16-bit binary representations can be obtained by another 16-bit binary representation by looping left several bits.

The difference between a circular left shift and a normal left shift is that the leftmost bit will be moved to the far right after the left one is cycled. Like what:
1011 0000 0000 0001 After a loop left one, it becomes 0110 0000 0000 0011, if the loop moves left 2 bits, it becomes 1100 0000 0000 0110

Input:

The first line is an integer n, 0 < n < 300000, indicating that there are still n rows of data behind
followed by n rows, with two non-negative integers not greater than 65535 per line

Output:

For two integers per line, output a line with Yes or no

Sample input:
42 49 1845057) 491587 12
Sample output:
Yesyesyesno
Source:
2010 Peking University computer Research Life Test real problem
Answering:
Problem solving problems? to discuss topics please visit: http://t.jobdu.com/thread-7874-1-1.html
code:
#include <cstdio>bool cmp (unsigned short A, unsigned short b) {    const int N = sizeof (unsigned short) * 8;    for (int i = 0; i < N; ++i) {        unsigned short t = (b << i) | (b >> (n-i));        if (t = = a) {            return true;        }    }    return false;} int main () {    int n = 0;    while (scanf ("%d", &n)! = EOF) {for        (int i = 0; i < n; ++i) {            unsigned short, a, b;            scanf ("%hu%hu", &a, &b);            if (CMP (A, B)) {                printf ("yes\n");            } else {                printf ("no\n");    }}} return 0;}

Topic 1151: Bit manipulation exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.