HDU多校1003-Divide the Stones(构造)
The weight of the i-th stone is i kilograms. We divide the stones into k groups.
Each group consists of exactly stones.
We define the weight of each group is sum of the stones’ weights in the group.
Can we divide the stones so that the weights of all groups are same?
Each test case consists of one line containing two integers n (1 ≤ n ≤ 100000), k (k is divisor of n).
It is guaranteed that the sum of n overall test cases does not exceed 500000.
Else if you can divide into k groups satisfying condition, print “yes” in one line and then print k lines.
The i-th line represent the indices of stones belonging to the i-th group.
If there are multiple solutions, you can print any of them.
4 2
1 4
2 3

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+; typedef long long ll;
using namespace std;
vector<int>vec[maxn];
int vis[maxn];
int main()
{
int T;
cin>>T;
ll n,k;
while(T--)
{
scanf("%lld%lld",&n,&k);
ll sum=(n*(n+)/);
for(int t=; t<=k; t++)
{
vec[t].clear();
}
memset(vis,,sizeof(vis));
if(sum%k!=)
{
puts("no");
}
else
{
if((n/k)%==)
{
puts("yes");
int cnt=;
for(int j=; j<=n/k; j++)
{
if(j%==)
{
for(int t=; t<=k; t++)
{
vec[t].push_back(cnt++);
}
}
else
{
for(int t=k; t>=; t--)
{
vec[t].push_back(cnt++);
}
}
}
for(int t=; t<=k; t++)
{
for(int j=; j<vec[t].size(); j++)
{
if(j!=vec[t].size()-)
printf("%d ",vec[t][j]);
else
{
printf("%d",vec[t][j]);
}
}
printf("\n");
}
}
else
{
puts("yes");
if(n==)
{
puts("");
continue;
}
ll kk=(*k+)/;
ll ss=k/+; int cnt=;
vec[].push_back(cnt);
vec[].push_back(kk-cnt);
int cnt1=cnt;
int cnt2=kk-cnt;
for(int t=;t<=k;t++)
{
if(t%==)
{
int temp1=cnt1+ss,temp2=cnt2-abs(k-ss);
vec[t].push_back(temp1);
vec[t].push_back(temp2);
cnt1=temp1;
cnt2=temp2;
}
else
{
int temp1=cnt1-abs(k-ss),temp2=cnt2+ss;
vec[t].push_back(temp1);
vec[t].push_back(temp2);
cnt1=temp1;
cnt2=temp2;
} }
cnt=*k+;
for(int j=; j<=n/k-; j++)
{
if(j%==)
{
for(int t=; t<=k; t++)
{
vec[t].push_back(cnt++);
}
}
else
{
for(int t=k; t>=; t--)
{
vec[t].push_back(cnt++);
}
}
}
for(int t=; t<=k; t++)
{
for(int j=; j<vec[t].size(); j++)
{
if(j!=vec[t].size()-)
printf("%d ",vec[t][j]);
else
{
printf("%d",vec[t][j]);
}
}
printf("\n");
}
}
}
}
return ;
}
HDU多校1003-Divide the Stones(构造)的更多相关文章
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
- 2015 HDU 多校联赛 5363 Key Set
2015 HDU 多校联赛 5363 Key Set 题目: http://acm.hdu.edu.cn/showproblem.php? pid=5363 依据前面给出的样例,得出求解公式 fn = ...
- 2015 HDU 多校联赛 5317 RGCDQ 筛法求解
2015 HDU 多校联赛 5317 RGCDQ 筛法求解 题目 http://acm.hdu.edu.cn/showproblem.php? pid=5317 本题的数据量非常大,測试样例多.数据 ...
- [HDU多校]Ridiculous Netizens
[HDU多校]Ridiculous Netizens 点分治 分成两个部分:对某一点P,连通块经过P或不经过P. 经过P采用树形依赖背包 不经过P的部分递归计算 树型依赖背包 v点必须由其父亲u点转移 ...
- hdu多校第四场 1003 (hdu6616) Divide the Stones 机智题
题意: 给你重量分别为1到n的n个石头,让你分成重量相等,数量也相等的k组,保证k是n的约数.问你能不能分配,如果能,输出具体的分配方案. 题解: 首先,如果1到n之和不能整除k,那么一定不能如题意分 ...
- [2019杭电多校第四场][hdu6616]Divide the Stones
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6616 题意是说n个数分别为1-n,将n个数分成k堆,能否满足每堆个数相等,数值之和相等.保证n%k=0 ...
- HDU - 6400 多校8 Parentheses Matrix(构造)
Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Oth ...
- 【HDOJ6616】Divide the Stones(构造)
题意:给定n堆石子,第i堆的个数为i,要求构造出一种方案将其分成k堆,使得这k堆每堆数量之和相等且堆数相等 保证k是n的一个约数 n<=1e5 思路:先把非法的情况判掉 n/k为偶数的方法及其简 ...
随机推荐
- 十分钟搭建自己的私有NuGet服务器-BaGet
目录 前言 开始 搭建BaGet 上传程序包 在vs中使用 其他 最后 前言 NuGet是用于微软.NET(包括 .NET Core)开发平台的软件包管理器.NuGet能够令你在项目中添加.移除和更新 ...
- hashMap在jdk1.7与jdk1.8中的原理及不同
在分析jdk1.7中HashMap的hash冲突时,不知大家是否有个疑问就是万一发生碰撞的节点非常多怎么版?如果说成百上千个节点在hash时发生碰撞,存储一个链表中,那么如果要查找其中一个节点,那就不 ...
- Go:内存管理与内存清理
Illustration created for "A Journey With Go", made from the original Go Gopher, created by ...
- Android Studio--家庭记账本(三)
点击右上角可以实现将花费以折线图的形式显示出来.同时将同一天的花费自动计算.暂时还没有加x,y轴 ChartsActivity.java: package com.example.family; im ...
- PyTorch上路
PyTorch torch.autograd模块 深度学习的算法本质上是通过反向传播求导数, PyTorch的autograd模块实现了此功能, 在Tensor上的所有操作, autograd都会为它 ...
- 02树莓派4B—C语言编程——PWM
01树莓派直接输出PWM波 —— 硬件PWM程序 (推荐使用) #include <stdio.h> #include <wiringPi.h> #include <s ...
- HahMap(jdk=1.8)源码解读
简介:岁月磨平了人的棱角,让我们不敢轻易的去放手,即使它在你心中并不那么重要,你依旧害怕失去它,不是舍不得,是内心的迷茫. 一 : 创建HashMap HashMap<Object, Objec ...
- 学长小清新题表之UOJ 14.DZY Loves Graph
学长小清新题表之UOJ 14.DZY Loves Graph 题目描述 \(DZY\)开始有 \(n\) 个点,现在他对这 \(n\) 个点进行了 \(m\) 次操作,对于第 \(i\) 个操作(从 ...
- 面试现场:裸面京东JavaT5第一轮电话面试
人物简介 清辞女朋友,94年资深女程序员一枚,15年非本专业毕业,有过1年测试经验,3年Java开发经验,之前有个1年大公司的工作经历,2年的车联网公司经历,每天打卡式工作,朝九晚七.工作之余没看过一 ...
- java+opencv人脸识别程序2.0
由于第一次写的太粗糙了,所以又修改了一下,详细的更改如下: @ 目录 更改 窗口问题 识别问题 相似度对比 仍然存在的问题 人脸信息显示 图片质量 更改 优化了一下界面风格 窗口问题 原来是在主界面外 ...