Abood's birthday has come, and his n friends are aligned in a single line from 1 to n, waiting for their cookies, Abood has x cookies to give to his friends.

Here is an example to understand how Abood gives away the cookies. Suppose Abood has 4 friends and x cookies, then Abood will do the following:

  1. Give a cookie to the 1st friend.
  2. Give a cookie to the 2nd friend.
  3. Give a cookie to the 3rd friend.
  4. Give a cookie to the 4th friend.
  5. Give a cookie to the 3rd friend.
  6. Give a cookie to the 2nd friend.
  7. Give a cookie to the 1st friend.
  8. Give a cookie to the 2nd friend.
  9. And so on until all the x cookies are given away.

Your task is to find how many cookies each friend will get. Can you?

Input

The first line contains an integer T (1 ≤ T ≤ 100) specifying the number of test cases.

Each test case consists of a single line containing two integers x and n (1 ≤ x ≤ 1018, 1 ≤ n ≤ 1000), in which x is the number of cookies Abood has, and n is the number of his friends.

Output

For each test case, print a single line containing n space-separated integers a1, ..., an, in which ai represents how many cookies the ith friend got.

Example
Input
1
5 3
Output
2 2 1

解题思路:我将蛋糕的分配方式模拟一下
- - - - - - -
- - - - - -
  - - - - - -
- - - - - - 
  - - - - - -
      - - -

我们可以看到的是:第一行每一个人都有,然后开始的奇数个前N-1个有,偶数个后N-1有,最后一行再判断是第奇数个还是偶数个就可以得出结果。

注意的是:没跑完第一行的情况需要特判一下,跑完第一行但是m<n也需要特判一下。


 #include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long int
using namespace std;
int main()
{
int t;
LL i,j,a[],m,n,x,y;
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
scanf("%lld%lld",&m,&n);
if(n==)///特判一下当n为1的时候
{
printf("%lld\n",m);
}
else if(m<n)
{
for(i=;i<m;i++)
{
a[i]=;
}
for(i=;i<n;i++)///只有前m个人有蛋糕,后面的人没有了蛋糕
{
if(i==n-)
{
printf("%lld\n",a[i]);
}
else
{
printf("%lld ",a[i]);
}
} }
else
{
for(i=;i<n;i++)///第一行的分配
{
a[i]=;
}
m=m-n;///分配完第一行之后剩下的蛋糕数量
x=m/(n-);///x表示剩下的行数
y=m%(n-);///y表示最后一行余下的蛋糕份数
for(i=;i<n-;i++)
{
a[i]=a[i]+x;///除了第一个人和最后一个人其他的人再得到x份蛋糕
}
///下面是对第一个人和最后一个人以及最后一行的蛋糕分配
if(x%==)///行数为偶数
{
a[]=a[]+x/;
a[n-]=a[n-]+x/;
for(i=n-;i>=n--y+;i--)
{
a[i]++;
}
}
else///行数为奇数
{
a[]=a[]+x/+;
a[n-]=a[n-]+x/;
for(i=;i<=y;i++)
{
a[i]=a[i]+;
}
}
}
for(i=;i<n;i++)///输出
{
if(i==n-)
{
printf("%lld\n",a[i]);
}
else
{
printf("%lld ",a[i]);
}
}
}
return ;
}

Friends and Cookies(思维)的更多相关文章

  1. 官方解析Cookies和Session的区别

      官方理解: Cookie机制 Cookie机制 Cookie是服务器存储在本地计算机上的小块文本,并随每个请求发送到同一服务器. IETF RFC 2965 HTTP状态管理机制是一种通用的coo ...

  2. 455. Assign Cookies 满足欲望 分配饼干

    [抄题]: Assume you are an awesome parent and want to give your children some cookies. But, you should ...

  3. 1. sqlmap超详细笔记+思维导图

    sqlmap思维导图: 基本操作笔记: -u #注入点 -f #指纹判别数据库类型 -b #获取数据库版本信息 -p #指定可测试的参数(?page=1&id=2 -p "page, ...

  4. 【面试题资源共享】一文总结最高频软件测试|sq|语句|思维发散|计算机基础|Linux|测试用例|接口测试|等技术面试题

    思维发散 1.一个球, -把尺子长度是球直径的2/3,怎样测出半径?2.四枚硬币,花面朝上,每次翻转三个,几次可以将四枚硬币变为字面朝上?3. U2合唱团在1 7分钟内赶到演唱会现场问题?4.小明一家 ...

  5. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  6. Photoshop、Illustrator思维导图笔记

    半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.

  7. CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维

    前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...

  8. 计算机程序的思维逻辑 (8) - char的真正含义

    看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...

  9. 计算机程序的思维逻辑 (29) - 剖析String

    上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...

随机推荐

  1. 在正文部分操作accordion内容展开和闭合

    $('#accordionid').accordion("select",0);             //展开第一个title $('#accordionid').accord ...

  2. php 后端刷新页面

    public function index() { $b = date('Y-m-d H:i:s'); header('refresh:10'); $c = strtotime($b); $d = s ...

  3. mysql 生成UUID() 即 ORACLE 中的guid()函数

    MYSQL 生成UUID 即 guid 函数-- 带 - 的UUIDselect UUID() -- 去掉 - 的UUIDselect replace(uuid(),'-','') 一个表的数据插入另 ...

  4. PHP程序员的技术成长规划 第三阶段:高级阶段

    第三阶段:高级阶段 (高级PHP程序员)重点:除了基本的LNMP程序,还能够在某个方向或领域有深入学习.(纵深维度发展)目标:除了能够完成基本的PHP业务开发,还能够解决大部分深入复杂的技术问题,并且 ...

  5. day89 DjangoRsetFramework学习---restful规范,解析器组件,Postman等

     DjangoRsetFramework学习---restful规范,解析器组件,Postman等           本节目录 一 预备知识 二 restful规范 三 DRF的APIView和解析 ...

  6. urllib库使用方法1 request

    urllib是可以模仿浏览器发送请求的库,Python自带 Python3中urllib分为:urllib.request和urllib.parse import urllib.request url ...

  7. jenkins+maven+docker集成java发布(二)#远程发布

    jenkins+maven+docker集成java发布(一)中写了在Jenkins服务器自动部署业务,那需要将java项目部署到其他服务器怎么操作 这里需要依赖插件Publish Over SSH ...

  8. golang 项目实战简明指南

    原文地址 开发环境搭建 golang 的开发环境搭建比较简单,由于是编译型语言,写好 golang 源码后,只需要执行 go build 就能将源码编译成对应平台(本文中默认为 linux)上的可执行 ...

  9. FPGA千兆网UDP协议实现

    接着上一篇百兆网接口的设计与使用,我们接着来进行FPGA百兆网UDP(User Datagram Protocol)协议的设计. 1)UDP简介 在此,参考博主夜雨翛然的博文“https://www. ...

  10. 20155310 2016-2017-2《Java程序设计》课堂实践补交

    20155310 2016-2017-2<Java程序设计>课堂实践补交 第九周 程序设计中临时变量的使用 public class linshibianliang { public st ...