博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Friends and Cookies(思维)
阅读量:5297 次
发布时间:2019-06-14

本文共 2278 字,大约阅读时间需要 7 分钟。

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也需要特判一下。

 
1 #include
2 #include
3 #include
4 #define LL long long int 5 using namespace std; 6 int main() 7 { 8 int t; 9 LL i,j,a[10010],m,n,x,y;10 scanf("%d",&t);11 while(t--)12 {13 memset(a,0,sizeof(a));14 scanf("%lld%lld",&m,&n);15 if(n==1)///特判一下当n为1的时候16 {17 printf("%lld\n",m);18 }19 else if(m
=n-2-y+1;i--)57 {58 a[i]++;59 }60 }61 else///行数为奇数62 {63 a[0]=a[0]+x/2+1;64 a[n-1]=a[n-1]+x/2;65 for(i=1;i<=y;i++)66 {67 a[i]=a[i]+1;68 }69 }70 }71 for(i=0;i

 

 

转载于:https://www.cnblogs.com/wkfvawl/p/9386106.html

你可能感兴趣的文章
tensorflow的graph和session
查看>>
JavaScript动画打开半透明提示层
查看>>
Mybatis生成resulteMap时的注意事项
查看>>
jquery-jqzoom 插件 用例
查看>>
1007. Maximum Subsequence Sum (25)
查看>>
iframe的父子层跨域 用了百度的postMessage()方法
查看>>
图片生成缩略图
查看>>
动态规划 例子与复杂度
查看>>
查看oracle数据库的连接数以及用户
查看>>
【数据结构】栈结构操作示例
查看>>
中建项目环境迁移说明
查看>>
三.野指针和free
查看>>
activemq5.14+zookeeper3.4.9实现高可用
查看>>
TCP/IP详解学习笔记(3)IP协议ARP协议和RARP协议
查看>>
简单【用户输入验证】
查看>>
python tkinter GUI绘制,以及点击更新显示图片
查看>>
HDU4405--Aeroplane chess(概率dp)
查看>>
CS0103: The name ‘Scripts’ does not exist in the current context解决方法
查看>>
20130330java基础学习笔记-语句_for循环嵌套练习2
查看>>
Spring面试题
查看>>