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 ...
随机推荐
- Axure之添加点击页面
添加悬停字体变色的效果 页面载入时的频道预设(我做错了,英文版本不知道那个是页面载入时的事件) 我的博客不够完善,看不到全部的图片.我后续会修改我的网站的
- git出现“The file will have its original line endings in your working directory”错误
一.现象: git add *时出现如下现象: The file will have its original line endings in your working directory 解决: G ...
- pip 异常问题
场景:安装的python版本为3.6.4 在使用pip命令时,出现错误:Did not provide a command 如下图所示: 解决办法:pip带上后缀.exe 为什么会出现这种情况? 主要 ...
- 计算机网络.{wireshark的使用实验}
---恢复内容开始--- 三种选择 1 2 3 端口镜像:交换机的某个端口,接受或者发送的数据给另外一个端口 ARP欺骗: ARP欺骗是利用ARP协议自身的不足进行的欺骗 1 执行ping命令, 2 ...
- list reverse
You can make use of the reversed function for this as: >>> array=[0,10,20,40] >>> ...
- 深入浅出Cocoa之消息【转】
在入门级别的ObjC 教程中,我们常对从C++或Java 或其他面向对象语言转过来的程序员说,ObjC 中的方法调用(ObjC中的术语为消息)跟其他语言中的方法调用差不多,只是形式有些不同而已. 譬如 ...
- SPSS统计基础-均值功能的使用
SPSS统计基础-均值功能的使用 均值过程计算一个或多个自变量类别中因变量的子组均值和相关的单变量统计.您也可以获得单因素方差分析.eta 和线性相关检验. 统计量.合计.个案数.均值.中位数.组内中 ...
- vue 保存数组和对象, 避免双向绑定影响
很多时候需要保存数据然后复用该数据,因vue的双向绑定总是不能保存原始数据 随笔记录解决方式 1. 不要把变量放置在data中 2. 保存至新的变量 object : let obj= Objec ...
- Linux的一些简单命令操作总结
防火墙 查看防火墙状态 systemctl status iptables (或service iptables status) 关闭防火墙 systemctl stop iptables(或serv ...
- LocalDateTime计算时间差
LocalDateTime 为java8的新特性之一 LocalDateTime.now() 获得当前时间 java.time.Duration duration = java.time.Durati ...