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. java环境变量配置(win7)

    JDK1.8 1.单击“计算机-属性-高级系统设置”,单击“环境变量”.在“系统变量”栏下单击“新建”,创建新的系统环境变量. 2.  (1)新建->变量名"JAVA_HOME&quo ...

  2. SDL2 undefined reference to `SDL_Init' 问题

    我在使用SDL2的时候,遇到undefined reference to `SDL_Init'的问题,只要使用SDL2相关的函数,就会报函数未定义.后来百度到一篇文章https://blog.csdn ...

  3. 腾讯云的对象存储COS

    什么是对象存储COS Clound Object Storage,COS,专门为企业和开发者们提供能够存储海量的分布式存储服务,用户可以随时通过互联网对大量数据进行批量存储和处理,在任意位置存储和检索 ...

  4. jQuery实现全选、全不选以及反选操作

    在写购物车案例时实现全选操作使用的是js的getAttribute()setAttribute()方法获取checked属性的值是undefined实现完成之后全选操作,如果在全选中的情况下改变其中一 ...

  5. 解决vscode换行光标跳转行首

    这个问题是由于设置自动保存而造成的. 解决方法1:取消自动保存. 解决方法2:在首选项的设置里加上"files.autoSaveDelay": 10000,延迟一小会自动保存的时间 ...

  6. 一张图一个表——CSS选择器总结

    CSS选择器总结: (这些表是一张图片^_^) 看底部 完整思维导图图片和表格的下载地址:https://download.csdn.net/download/denlnyyr/10597820 (我 ...

  7. Redis之Redis持久化

    Redis(Remote Dictionary Server)是一个可持久化的内存.Key-Value数据库. 作为内存数据库,为了防止因服务器断电或系统宕机而引起的数据丢失问题,Redis自带了持久 ...

  8. 文库网站建设,文库网站PHP代码,TP开发文库网

    专业定制仿百度文库网站系统,文库网站系统源码,文库‌‌网站建设开发,支持电脑版+手机版+微信版+小程序版+APP版,由10年的技术团队专业定制,需要的朋友可以联系我们.网站采用:PHP+MySQL+t ...

  9. ruby rspec+jenkins+ci_report持续集成生成junit测试报告

    1.加载ci_report gem install ci_reporter_rspec 2.给测试工程编写rakefile require 'ci/reporter/rake/rspec' requi ...

  10. 学号20155311 2016-2017-2 《Java程序设计》第6周学习总结

    学号20155311 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 输入/输出 10.1 InputStream与OutputStream Inpu ...