codeforces A. Candy Bags 解题报告
题目链接: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 解题报告的更多相关文章
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces C. Inna and Huge Candy Matrix 解题报告
题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- 【LeetCode】723. Candy Crush 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 日期 题目地址:https://leetcode ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces 581C. Developing Skills 解题报告
题目链接:http://codeforces.com/problemset/problem/581/C 题目意思:给出 n 个数:a1, a2, ..., an (0 ≤ ai ≤ 100).给出值 ...
随机推荐
- 利用getHibernateTemplate实现简单的操作
package org.tarena.dao; import java.sql.SQLException; import java.util.List; import javax.annotation ...
- session共享
Nginx或者Squit反向代理到两台tomcat服务器 tomcat使用memcached tomcat连接memcached工具 cp session/*.jar /usr/local/tomca ...
- linux内核数据结构学习总结
目录 . 进程相关数据结构 ) struct task_struct ) struct cred ) struct pid_link ) struct pid ) struct signal_stru ...
- iOS代码工具箱再续
if (CGRectContainsPoint(self.menuView.frame, point)) { point = [self.view convertPoint:point toView ...
- c#中的23种设计模式
C# 23种设计模式汇总 创建型模式 工厂方法(Factory Method) 在工厂方法模式中,工厂方法用来创建客户所需要的产品,同时还向客户隐藏了哪种具体产品类将被实例化这一细节.工厂方法模式的核 ...
- User表格式
"_id":基本是700多 "name":"xx01" "pwd":"123"
- Java多线程基础(一)
一.基本概念 线程状态图包括五种状态 1.新建状态(New):线程对象被创建后,就进入新建状态.例如,Thread thread=new Thread(); 2.就绪状态(Runnable):也被称为 ...
- tomcat Host及Context 配置
参考资料: 一.Host配置 对一个Tomcat,可以配置多台虚拟主机.简单地说,就是让一台服务器可以对应多个主机名.这在Tomcat中称之为Host.要求每个Host的Name必须唯一. 配置方法: ...
- What to call your Academic Event
- Color Space
色域(Color Space),又被称为色彩空间,它代表了一个色彩影像所能表现的色彩具体情况.我们经常用到的色彩空间主要有RGB.CMYK.Lab等,而RGB色彩 空间又有AdobeRGB.Apple ...