题目链接:http://codeforces.com/contest/334/problem/A

题意:有n个人,将1~n袋(第 i  袋共有 i  颗糖果,1<= i  <=n)所有的糖果(n*(n+1)/2)均分到n个人中。

这里要注意的是输出问题,每行中的前n / 2(包括n/2)个数比较容易解决,就是每两个数中相隔n个长度,第n/2个数和第n/2+1个数之间隔了多少个长度,这是值得考虑的问题。我的做法是,由于每个人分到的糖果是 (n / 2) * (n*n+1)  (输出的n个数看成n/2个组合,每个组合有两个数,这两个数中的和恰好是n*n+1),所以用一个数组存储后半部分n/2+1 ~ n。例如输入的n为6,输出如下:

第一个人:  1     7      13   24  30  36

第二个人:  2   8     14   23  29  35

第三个人:  3   9     15    22  28  34

第四个人:  4   10        16    21       27       33

第五个人:    5         11        17         20        26      32

第六个人:  6   12         18        19        25      31

以第一个人作为分析:1和36是一个组合,另外两个组合分别是7和30,13和24,当输出1的时候,计算出36(6*6+1-1),存入temp[0],输出7的时候,计算出30(37-7),存入temp[1],输出13,计算出24,存入temp[2],最后按逆序(2--->0)输出即可。可能方法有点笨,希望热心的读者可以提出些更好的方法,让我学习学习。

 #include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std; const int maxn = + ; int main()
{
int i, j, k, l, n, temp[maxn];
while (scanf("%d", &n) != EOF)
{
for (i = ; i <= n; i++)
{
k = ;
for (j = i; j <= (n * n / ); j += n)
{
if (j == i)
printf("%d", j);
else
printf(" %d", j);
temp[k++] = n * n + - j;
}
for (l = n / -; l >= ; l--)
{
printf(" %d", temp[l]);
}
printf("\n");
}
}
return ;
}

codeforces A. Candy Bags 解题报告的更多相关文章

  1. Codeforces Round 665 赛后解题报告(暂A-D)

    Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...

  2. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  3. Codeforces Round #277.5 解题报告

    又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...

  4. codeforces C. Inna and Huge Candy Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal ...

  5. codeforces B. Simple Molecules 解题报告

    题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...

  6. 【LeetCode】723. Candy Crush 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 日期 题目地址:https://leetcode ...

  7. codeforces 591A. Wizards' Duel 解题报告

    题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...

  8. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  9. codeforces 581C. Developing Skills 解题报告

    题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...

随机推荐

  1. 【BZOJ-1588】营业额统计 Splay

    1588: [HNOI2002]营业额统计 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 12485  Solved: 4508[Submit][Sta ...

  2. POJ1703Find them, Catch them

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37722   Accepted: ...

  3. 基于redis分布式缓存实现

    Redis的复制功能是完全建立在之前我们讨论过的基 于内存快照的持久化策略基础上的,也就是说无论你的持久化策略选择的是什么,只要用到了Redis的复制功能,就一定会有内存快照发生,那么首先要注意你 的 ...

  4. CentOS 6.4 32位系统 LAMP(Apache+MySQL+PHP)安装步骤

    先来解释一下,什么是 LAMP.正如标题所言,LAMP 实际上就是 Linux.Apache.MySQL.PHP 四个名称的缩写,当然最后一个 “P” 还有其他说法是 Perl 或者 Python.不 ...

  5. html标签页图标

    在head标签加入如下内容: <!--可以在收藏夹中显示出图标--> <link rel="Bookmark" type="image/png" ...

  6. MyBatis查询传一个参数时报错:There is no getter for property named 'sleevetype' in 'class java.lang.Integer

    用MyBatis进行查询,传入参数只有一个时(非Map)如int,报错 There is no getter for property named 'sleevetype' in 'class jav ...

  7. DEEP LEARNING WITH STRUCTURE

    DEEP LEARNING WITH STRUCTURE Charlie Tang is a PhD student in the Machine Learning group at the Univ ...

  8. Unable to open liblaunch_sim.dylib. Try reinstalling Xcode or the simulator

    关于Xcode7 Beta报错 simulator runtime is not available. Unable to open liblaunch_sim.dylib Try reinstall ...

  9. Js日期选择器并自动加入到输入框中

    <html> <head> <title>Js日期选择器并自动加入到输入框中</title> <meta http-equiv="con ...

  10. 安装TFS2008最终版(转载)

    一.安装操作系统:windows server 2003 + Sp2具体步骤: 1.安装windows server 2003时选用工作组(默认为workgroup).由于在工作组环境中部署,因此使用 ...