当前位置:网站首页>4461. Range Partition (Google Kickstart2022 Round C Problem B)
4461. Range Partition (Google Kickstart2022 Round C Problem B)
2022-07-30 06:06:00 【Zhang Xueheng】
1:题目
Ellen and Barbara play a numbers game together.
给定前 N 个正整数 1∼N.
首先,It's up to Allen to pick some numbers out of them(不能不取),然后,Barbara selects all the remaining numbers(如果有的话).
Let the sum of all the numbers Allen pick be A,The sum of all numbers chosen by Barbara is B.
现在,given a ratio X:Y,要求 A:B 恰好等于 X:Y.
Could you please give a reasonable scheme for Allen to choose the numbers.
输入格式
第一行包含整数 T,表示共有 T 组测试数据.
每组数据占一行,包含三个整数 N,X,Y.
输出格式
Each set of data first outputs a row of results,形如 Case #x: y,其中 x 为组别编号(从 1 开始),y 为 POSSIBLE(A reasonable solution exists),或 IMPOSSIBLE(There is no reasonable solution).
如果A reasonable solution exists,Then there are two more lines of results to output,第一行输出一个整数,Represents the number of digits that Allen picks,The second line outputs the numbers selected by Allen.
如果答案不唯一,则输出任意合理方案均可.
数据范围
1≤T≤100,
1≤X,Y≤108,
gcd(X,Y)=1,
1≤N≤5000.
输入样例:
3
3 1 2
3 1 1
3 1 3
输出样例:
Case #1: POSSIBLE
1
2
Case #2: POSSIBLE
2
1 2
Case #3: IMPOSSIBLE
样例解释
对于 Case 1,Ellen chose 2,Barbara chose 1,3,因此 A=2,B=1+3=4,比率为 2:4,The ratio with the given ratio 1:2 相等.
对于 Case 2,Ellen chose 1,2,Barbara chose 3,因此 A=1+2=3,B=3,比率为 3:3,The ratio with the given ratio 1:1 相等.
对于 Case 3,There is no rational choice of numbers.
难度:简单
时/空限制:1s / 64MB
总通过数:387
总尝试数:881
来源:Google Kickstart2022 Round C Problem B
算法标签
None
2:代码实现
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 5010;
int n, x, y;
int ans[N];
int main()
{
int T;
cin >> T;
for (int t = 1; t <= T; t ++)
{
cin >> n >> x >> y;
int sum = 0;
for (int i = 1; i <= n; i ++) sum += i;
int b = sum / (x + y);
if (sum % (x + y)) printf("Case #%d: IMPOSSIBLE\n", t);
else
{
memset(ans, 0, sizeof ans);
printf("Case #%d: POSSIBLE\n", t);
int cnt = 0;
int s = x * b;
for (int i = n; i >= 1; i --)
{
if (s >= i)
{
s -= i;
ans[cnt ++] = i;
}
}
cout << cnt << endl;
for (int i = 0; i < cnt; i ++)
cout << ans[i] << ' ';
cout << endl;
}
}
}
边栏推荐
- SOA(面向服务架构)是什么?
- Summary of SQL classic interview questions in 2022 (with analysis)
- Falling ants (Peking University entrance exam questions)
- 分布式事务之 Seata框架的原理和实战使用(三)
- 2022年比若依更香的开源项目
- WeChat payment and payment callback
- 使用DataEase开源工具制作一个高质量的数据大屏
- curl (7) Failed connect to localhost8080; Connection refused
- MySQL-Explain详解
- asyncawait和promise的区别
猜你喜欢
net start mysql MySQL service is starting. MySQL service failed to start.The service did not report any errors.
MySQL Soul 16 Questions, how many questions can you last?
Teach you to completely uninstall MySQL
JVM之GC 调优工具 Arthas 实战使用(二)
Programmers make money and practice, teach you how to do paid courses, self-media, paid articles and paid technical courses to make money
More fragrant open source projects than Ruoyi in 2022
[Image processing] Image skeleton extraction based on central axis transformation with matlab code
【图像处理】基于中轴变换实现图像骨架提取附matlab代码
MySQL stored procedure
idea 编译protobuf 文件的设置使用
随机推荐
[GO语言基础] 一.为什么我要学习Golang以及GO语言入门普及
手把手教你设计一个CSDN系统
Summary of SQL classic interview questions in 2022 (with analysis)
子查询作为检索表时的不同使用场景以及是否需要添加别名的问题
[其他] DS5
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
ClickHouse data insert, update and delete operations SQL
面试题 17.13. 恢复空格(字典树)
Falling ants (Peking University entrance exam questions)
成绩排序(华中科技大学考研机试题)(DAY 87)
[Koltin Flow (1)] Five ways to create flow
Concurrent Programming Review
Path dependence: the poor hard science to counter attack breakthrough
手把手教你彻底卸载MySQL
MySQL kills 10 questions, how many questions can you stick to?
429. N 叉树的层序遍历(两种解法)
navicat新建数据库
微信小程序开发学习
Basic syntax of MySQL DDL and DML and DQL
期末作业C#实现学生宿舍管理系统