本文主要是介绍UVALive 5783 Everyone out of the Pool,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3794
When you rent a table at a pool hall, the proprietor gives you a 4-by-4 tray of 16 balls, as shown in Figure (a) below. One of these balls, called the ``cue ball", is white, and the remaining 15 are numbered 1 through 15. At the beginning of a game, the numbered balls are racked up in a triangle (without the cue ball), as shown in Figure (b).

Now imagine other pool-like games where you have a cue ball and x numbered balls. You'd like to be able to rack up the x numbered balls in a triangle, and have all x + 1 balls perfectly fill a square m-by-m tray. For what values of x is this possible? In this problem you'll be given an lower bound a and upper bound b, and asked how many numbers within this range have the above property.
输入
Input for each test case will one line containin two integers a b, where 0 < a < b109. The line `0 0' will follow the last test case.
输出
For each test case one line of output as follows:
Case n: k
if there are k integers x such that a < x + 1 < b, x balls can be racked up in a triangle, and x + 1 balls fill a square tray.
输入
15 17 14 16 1 20 0 0
输出
Case 1: 1 Case 2: 0 Case 3: 2题意:水题,球数为x时,既可以排成m*m正方形形状,减一求又可以排成正三角形。求b到c间x的个数。
代码:
#include <stdio.h>
#include <string.h>
int all[44750], sign[44750];
int ok(int x){for (int i = 0; i < 44750; i++){if (all[i] == x)return 1;}return 0;
}
int ok2(int x){for (int i = 0; i < 44750; i++){if (sign[i] == x)return 1;}return 0;
}
int main()
{int cnt = 1, use = 3;all[0] = 3;for (int x = 3; x < 1000000010;){x += use;use++;all[cnt++] = x;}memset(sign, 0, sizeof(sign));int end = 0;for (int i = 2; i*i < 1000000010; i++){if (ok(i*i - 1))sign[end++] = i*i - 1;}int a, b, C = 1;while (scanf("%d%d", &a, &b) != EOF){int ans = 0;if (a == 0 && b == 0)return 0;for (int i = 0; i < end; i++){if (sign[i]>(a - 1) && sign[i] < (b - 1))ans++;}printf("Case %d: %d\n", C++, ans);}return 0;
}
这篇关于UVALive 5783 Everyone out of the Pool的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!