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为偶数的方法及其简 ...
随机推荐
- ios 富文本 加颜色 删除线
UILabel *valueL = [JAppViewTools getLabel:CGRectMake(JFWidth(15), CGRectGetMaxY(proName.frame)+JFWid ...
- js 自定义属性操作
自定义属性操作 element.属性 获取内置属性值 element.getAttribute("属性") 我们自己添加的属性叫自定义属性 element. ...
- 2020-04-08:谈一下IOC底层原理
Ioc的底层原理 (1)xml配置文件 (2)dom4j解析xml (3)工厂设计模式 (4)反射
- C#算法设计排序篇之05-归并排序(附带动画演示程序)
归并排序(Merge Sort) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/683 访问. 归并排序是建立在归并操作 ...
- Spring/Springboot——JavaConfig
1.认识JavaConfig JavaConfig是Spring的一个子项目,在Spring4之后成为一个核心功能 JavaConfig中使用的注解: @Configuration 在类上打上这一标签 ...
- Code Review 从失败中总结出来的几个经验
资深的程序员都知道 Code Review 可以对代码质量,代码规范,团队代码能力提升带来很大的提升,还有著名的技术专家"左耳朵耗子"也说过: 我认为没有 Code Review ...
- Vue+Spring Boot 前后端分离的商城项目开源啦!
新蜂商城 Vue 移动端版本开源啦! 去年开源新蜂商城项目后,就一直在计划这个项目 Vue 版本的改造,2020 年开始开发并且自己私下一直在测试,之前也有文章介绍过测试过程和存在的问题,修改完成后, ...
- 记好这 24 个 ES6 方法,用来解决实际开发的 JS 问题
本文主要介绍 24 中 es6 方法,这些方法都挺实用的,本本请记好,时不时翻出来看看. 1.如何隐藏所有指定的元素 const hide = (el) => Array.from(el).fo ...
- unity探索者之安卓微信登录,非第三方插件
版权声明:本文为原创文章,转载请声明http://www.cnblogs.com/unityExplorer/p/7666348.html 之前写了两篇关于微信分享的博客,其实微信登录.分享.支付博主 ...
- 关于haar特征的理解及使用(java实现)
Haar特征原理综述Haar特征是一种反映图像的灰度变化的,像素分模块求差值的一种特征.它分为三类:边缘特征.线性特征.中心特征和对角线特征.如下所示: Haar-like矩形特征拓展 Lienha ...