UVALive 5783 Everyone out of the Pool

2024-08-23 03:38
文章标签 pool everyone uvalive 5783

本文主要是介绍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).

\epsfbox{p5783.eps}

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 < b$ \le$109. The line `0 0' will follow the last test case.

输出

For each test case one line of output as follows:


Case nk


if there are k integers x such that a < x + 1 < bx 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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1098245

相关文章

python测试开发基础---multiprocessing.Pool

1. 基础概念 多进程编程:Python中的multiprocessing模块允许你使用多个进程并行执行任务,这可以提高程序的性能,尤其是在需要大量计算的情况下。Pool类是一个常用工具,可以帮助你更轻松地管理多个进程。 进程池:进程池是一个包含多个工作进程的池子,用来处理多个任务。你可以将任务分配给池中的进程,池会自动管理这些进程。 2. 使用方法 以下是multiprocessing.

【python 多进程传参】pool.map() 函数传多参数

无意中发现了一个巨牛的人工智能教程,忍不住分享一下给大家。教程不仅是零基础,通俗易懂,而且非常风趣幽默,像看小说一样!觉得太牛了,所以分享给大家。点这里可以跳转到教程。人工智能教程 一、背景介绍 相信很多人都用过,pool.map()函数,这个函数,有两个参数可以传,第一个参数传的是函数,第二个参数传的是数据列表。 那么怎么在第二个数据列表,多传几个参数呢,方法是通过对有多个参数的方法进行封装

Vulkan描述符、描述符Pool、Layout概念

1、DescriptorSetLayout为了组织和管理着色器资源(如缓冲区、纹理、采样器等),多个相同类型的Descriptor放在一个Layout中以优化GPU对资源的访问   //DescriptorSetLayout定义了哪些描述符Descriptor类型(Buffers、Textures、Samplers)可以包含在其中 VkDescriptorSetLayoutBinding

【UVALive】6709 Mosaic 二维线段树

传送门:【UVALive】6709 Mosaic 题目大意: 每次选择矩阵中的一个点,求以他为中心,边长为D(D一定是奇数)的矩阵中的最小值min和最大值max,输出ans =(min+max)/ 2(向下取整)。然后将该点的值修改为ans。 题目分析: 赤果果的二维线段树单点修改、区间查询。 又一次学习了线段树,发现原来所有的更新操作全部放在二维中即可。 很不错,一定要经常看看,温

【UVALive】3887 Slim Span 枚举+最小生成树

传送门:【UVALive】3887 Slim Span 题目大意:给出一个n(2 <= n <= 100)个结点的无向图,找一棵苗条度(最大边减最小边的值)最小的生成树。图中不含自环或重边。 题目分析:枚举最小边求生成树即可。模板用用萌萌哒~ 代码如下: #include <cstdio>#include <cstring>#include <algorit

【UVALive】5713 Qin Shi Huang's National Road System 最小生成树

传送门:【UVALive】5713 Qin Shi Huang's National Road System 题目大意:秦朝有n个城市,需要修建一些道路使得任意两个城市之间都可以连通。道士徐福声称他可以用法术修路,不花钱,也不用劳动力,但只能修一条路,因此需要慎重选择用法术修哪一条路。秦始皇不仅希望其他道路的总长度B尽量短(这样可以节省劳动力),还希望法术连接的两个城市的人口之和A尽量大,因此下

【UVALive】3661 Animal Run 平面图最小割 最短路

传送门:【UVALive】3661 Animal Run 题目大意:给你一个n*m个点的网格图,其中动物园在左上角,动物们的目的地在右下角,现在你需要派出一些工作人员拦截某些边使得没有一只动物能到达右下角,已知每个单元网格中存在左上角到右下角的对角线,网格中的边以及对角线都是双向的,每条道路有个权值,表示拦截这条边所需要的工作人员数。你的任务是派尽量少的工作人员使得达到目的。 题目分析

【UVALive】2965 Jurassic Remains 中途相遇法

传送门:【UVALive】2965 Jurassic Remains 题目分析:本题用了一个很不错的思想——中途相遇法。 因为题目的数据很小,我们很容易想到暴力,但是2^24次方的枚举依旧复杂度太大,因此我们可以这么做:将一半的串枚举异或能得到的所有的值,插入到map中,然后再枚举异或另一半的串能得到的所有的值,然后查找map中的与这个值相同的有没有,更新一下能得到的最大数量即可。 成

【UVALive】6163 Myth Busters 类24点

传送门:【UVALive】6163 Myth Busters 题目分析: 可以使用括号,还有加减乘除,问能否用四个0~9的数凑出10。。。我了个去。。渣渣不会写拿来当模拟写了,写的人都要吐了。。。。 先处理出所有两个数和起来的情况,然后用两个数和起来的情况再加上一个数处理出所有三个数和起来的情况,最后用两个两个数或者一个三个数加一个数的继续推出四个数的,最后按照不降序保存。 这个能一

python并行计算之pool.apply_async()与pool.imap()的异同点

目录 1. 框架和技术概要: 🎨🖥️2. 相似点: 🧩💡3. 不同点: 📊👣4. 使用示例: 😊👨‍💻5. 总结: 🎉 1. 框架和技术概要: 🎨🖥️ multiprocessing 模块中的 pool.apply_async() 与 pool.imap() 都用于并行处理,但它们在使用方式和返回结果上有所不同。 2. 相似点: 🧩💡 并行处理