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. 创建Podfile,添加类库,中途添加库指令

    前提是你电脑已经安装了CocoaPods 1.打开终端 2.进入你的工程目录  cd /Users/...../CocoaPodsDemo  3. 创建Pods文件  touch Podfile 新建 ...

  2. swiper 导航有多个,被点击的项居中显示。

    <div class="swiper-container"> <div class="swiper-wrapper"> <div ...

  3. redis学习指南

    一.redis安装 # 安装最新版 yum install -y epel-release vim atop htop net-tools git wget gcc-c++ yum clean all ...

  4. GUN交叉工具链各模块的作用

    名称              归属                             作用 arm-linux-as          binutils     编译ARM 汇编程序  arm ...

  5. PHP-学习笔记-进阶

    PHP-学习笔记-进阶 PHP类和对象之定义类的方法 访问控制的关键字代表的意义为: public:公开的 protected:受保护的 private:私有的 我们可以这样定义方法: class C ...

  6. Vivado 调用自定义IP核

    关于Vivado如何创建自定义IP核有大量的参考文章,这里就不多加阐述了,本文目的主要是解决如何在新建工程中引用其它工程已经自定义封装好的IP核,从而实现自定义IP核的灵活复用. 举个例子,我们的目标 ...

  7. nodejs搭建web服务器初级

    nodejs搭建简单的web服务器 1.1简介 Node.js是基于Chrome JavaScript运行时建立的一个平台,实际上它是对Google Chrome V8引擎进行了封装,它主要用于创建快 ...

  8. 20145207《Java程序设计》实验二(Java面向对象程序设计)实验报告

    <Java程序设计>实验二(Java面向对象程序设计)实验报告 目录 改变 Java面向对象程序设计实验要求 实验成果 课后思考 改变 看了下之前实验二的整体,很搞笑,大图+代码,没了.. ...

  9. 深入理解redis复制原理

    原文:深入理解redis复制原理 1.复制过程 2.数据间的同步 3.全量复制 4.部分复制 5.心跳 6.异步复制 1.复制过程 从节点执行 slaveof 命令. 从节点只是保存了 slaveof ...

  10. java Hibernate UUID代码

    package mypack; import java.io.Serializable; import java.net.InetAddress; /** * 唯一主键生成办法.从Hibernate中 ...