hdu 3805 Triangle Conjecture
题意是给出边的长度的,求出边长相等的三角形,输出任意一种答案。边长是1~n的数,每个只能用一次。
其实比较容易可以看出,无论我们怎么操作,只要保持边长总和都是相邻整数就是了。例如现在得到长度为n,n+1,n+2的三条边,可以对应加上m+2,m+0,m+1,从而变成了s+1,s+0,s+2。反正我们在处理123之前,保持着总和是这样的结构就行了。然后最后到了123的时候就能对应加上去,使之相等。
代码如下:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring> using namespace std; const int N = ;
int arr[][N];
typedef pair<int, int> PII; void maketri(int n) {
int sum[];
int t = n;
n = (n - ) * ;
sum[] = (n << ) - ;
sum[] = (n << ) - ;
sum[] = (n << ) - ;
for (int i = ; i < ; i++) arr[i][arr[i][] = ] = n--;
PII tmp[];
while (n > ) {
for (int i = ; i < ; i++) tmp[i] = PII(sum[i], i);
sort(tmp, tmp + );
for (int i = ; i >= ; i--) {
int id = tmp[(i + ) % ].second;
sum[id] += n;
arr[id][++arr[id][]] = n--;
}
}
for (int i = ; i < ; i++) tmp[i] = PII(sum[i], i);
sort(tmp, tmp + );
for (int i = ; i < ; i++) {
int id = tmp[i].second;
sum[id] += n;
arr[id][++arr[id][]] = n--;
}
// for (int i = 0; i < 3; i++) {
// for (int j = 1; j <= arr[i][0]; j++) cout << arr[i][j] << ' '; cout << endl;
// }
printf("%d\n", arr[][]);
for (int i = ; i < t; i++) {
printf("%d %d\n", arr[][i], arr[][i]);
}
for (int i = ; i < t; i++) printf("%d ", arr[][i]);
printf("%d\n", arr[][]);
} int main() {
int T, n;
scanf("%d", &T);
while (T-- && ~scanf("%d", &n)) maketri(n);
return ;
}
——written by Lyon
hdu 3805 Triangle Conjecture的更多相关文章
- HDU 5914 Triangle 数学找规律
Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...
- hdu 4324 Triangle LOVE
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4324 Triangle LOVE Description Recently, scientists f ...
- HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))
Triangle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 5914 Triangle(打表——斐波那契数的应用)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Problem Description Mr. Frog has n sticks, whos ...
- HDU 4324 Triangle LOVE 拓扑排序
Problem Description Recently, scientists find that there is love between any of two people. For exam ...
- HDU 4324 Triangle LOVE (拓扑排序)
Triangle LOVE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- hdu 6512 Triangle
Problem Description After Xiaoteng took a math class, he learned a lot of different shapes, but Xiao ...
- HDU 6300.Triangle Partition-三角形-水题 (2018 Multi-University Training Contest 1 1003)
6300.Triangle Partition 这个题就是输出组成三角形的点的下标. 因为任意三点不共线,所以任意三点就可以组成三角形,直接排个序然后输出就可以了. 讲道理,没看懂官方题解说的啥... ...
- HDU——1397Goldbach's Conjecture(二分查找+素数打表)
Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
随机推荐
- 2019-7-3-WPF-使用-Composition-API-做高性能渲染
title author date CreateTime categories WPF 使用 Composition API 做高性能渲染 lindexi 2019-07-03 10:30:57 +0 ...
- python实例 字典
#! /usr/bin/python x={'a':'aaa','b':'bbb','c':12} print (x['a']) print (x['b']) print (x['c']) for k ...
- NOIP模拟题17.9.26
B 君的任务(task)[题目描述]与君初相识,犹如故人归.B 君看到了Z 君的第一题,觉得很难.于是自己出了一个简单题.你需要完成n 个任务,第i 任务有2 个属性ai; bi.其中ai 是完成这个 ...
- 【洛谷】P1880 石子合并
P1880 石子合并 题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计 ...
- 卡特兰数(catalan)总结
卡特兰数的公式 递推公式1:$f(n)=\sum \limits_{i=0}^{n-1}f(i)*f(n-i-1)$ 递推公式2:$f(n)=\frac{f(n-1)*(4*n-2)}{n+1}$ 组 ...
- 对于MD5加密处理方式
来源:http://blog.51cto.com/xqtesting/1924977 但有时候我们请求的参数可能需要加密,比如登录接口中的密码可能需要经过md5加密这时候怎么处理呢? 这种方法比较简单 ...
- 消息队列rabbitmq rabbitMQ安装
消息队列rabbitmq 12.1 rabbitMQ 1. 你了解的消息队列 生活里的消息队列,如同邮局的邮箱, 如果没邮箱的话, 邮件必须找到邮件那个人,递给他,才玩完成,那这个任务会处理的很麻 ...
- Google搜索技巧-入门篇
基本搜索 Google 查询简洁方便,仅需输入查询内容并敲一下回车键 (Enter),或单击“Google 搜索”按钮即可得到相关资料. 搜索两个及两个以上关键字 Google 只会返回那些符合您的全 ...
- vue中 表头 th 合并单元格,且表格列数不定的动态渲染方法
吐槽 今天,在vue中遇到 复杂表格的渲染 ,需要合并表头th的单元格,且合并单元格的那列的表头数据是动态数据,也就是不知道会有多少个表头列,而这几个表头列还分了好几个子表头. 这个需求在js里用Ju ...
- 一句python,一句R︱python中的字符串操作、中文乱码、NaN情况
一句python,一句R︱python中的字符串操作.中文乱码.NaN情况 先学了R,最近刚刚上手Python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句pytho ...