本文主要是介绍湖南多校对抗赛(2014.03.16) C.Pings,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Suppose you are tracking some satellites. Each satellite broadcasts a ‘Ping’ at a regular interval, and the intervals are unique (that is, no two satellites ping at the same interval). You need to know which satellites you can hear from your current position. The problem is that the pings cancel each other out. If an even number of satellites ping at a given time, you won’t hear anything, and if an odd number ping at a given time, it sounds like a single ping. All of the satellites ping at time 0, and then each pings regularly at its unique interval.
Given a sequence of pings and non-pings, starting at time 0, which satellites can you determine that you can hear from where you are? The sequence you’re given may, or may not, be long enough to include all of the satellites’ ping intervals. There may be satellites that ping at time 0, but the sequence isn’t long enough for you to hear their next ping. You don’t have enough information to report about these satellites. Just report about the ones with an interval short enough to be in the sequence of pings.
Input
There will be several test cases in the input. Each test case will consist of a single string on its own line, with from 2 to 1,000 characters. The first character represents time 0, the next represents time 1, and so on. Each character will either be a 0 or a 1, indicating whether or not a ping can be heard at that time (0=No, 1=Yes). Each input is guaranteed to have at least one satellite that can be heard. The input will end with a line with a single 0.Output
For each test case, output a list of integers on a single line, indicating the intervals of the satellites that you know you can hear. Output the intervals in order from smallest to largest, with a single space between them. Output no extra spaces, and do not separate answers with blank lines.
Sample Input01000101101000
1001000101001000
0
Sample Output
1 2 3 6 8 10 11 13
3 6 7 12 14 15
题目意思有点难懂,本题题意是: 输入一行字符串,代表从0-N这个时间段是否能收到信号,(当有偶数个机器同时发射信号时,收不到信号,奇数能)。要你求各个机器发射信号的间隔,0为始点。
代码:
#include <stdio.h>
#include <string.h>
int main()
{char a[1010];int sign[1010];while (scanf("%s", a) != EOF){int len;len = strlen(a);if (len == 1 && a[0] == '0')return 0;memset(sign, 0, sizeof(sign));for (int i = 1; i < len; i++){if (a[i] == '1'){sign[i] = 1;int u = i;for (int k = u + u; k < len; k += u){if (a[k] == '0')a[k] = '1';elsea[k] = '0';}}}int cnt = 0;for (int i = 0; i < len; i++){if (sign[i] == 1){cnt++;if (cnt == 1)printf("%d", i);elseprintf(" %d", i);}}printf("\n");}return 0;
}
这篇关于湖南多校对抗赛(2014.03.16) C.Pings的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!