HDU 1270 小希的数表 (暴力枚举+数学)
题意:...
析:我们可以知道,a1+a2=b1,那么我们可以枚举a1,那么a2就有了,并且a1+a3=b2,所以a3就有了,我们再从把里面的剩下的数两两相加,并从b数组中去掉,
那么剩下的最小的就是a4,然后依次可以求出a5,a6....由于a最大才是5000,并且保证有唯一解,那么找到一个就直接退出。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int b[maxn], c[maxn];
int a[maxn]; bool judge(int x){
a[1] = x; a[2] = b[1] - a[1];
int cnt = 2; for(int i = 2; i <= m; ++i){
if(b[i]) a[++cnt] = b[i] - a[1];
else continue;
for(int j = 2; j < cnt; ++j){
bool ok = false;
for(int k = i+1; k <= m; ++k) if(a[j] + a[cnt] == b[k]){
b[k] = 0;
ok = true;
break;
}
if(!ok) return ok;
}
}
return true;
} int main(){
while(scanf("%d", &n) == 1 && n){
m = n * (n-1) / 2;
for(int i = 1; i <= m; ++i) scanf("%d", c+i);
for(int i = 1; ; ++i){
memcpy(b+1, c+1, 4*m);
if(judge(i)) break;
}
for(int i = 1; i <= n; ++i)
if(i == 1) printf("%d", a[i]);
else printf(" %d", a[i]);
printf("\n"); }
return 0;
}
HDU 1270 小希的数表 (暴力枚举+数学)的更多相关文章
- hdu 1270 小希的数表
思路:一定有sum[1]=num[1]+num[2],sum[2]=num[1]+num[3]; 但是sum[3]不知道是由num[1]+num[4]还是num[2]+num[3],这就需要枚举一下了 ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...
- hdu 5491 The Next(暴力枚举)
Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...
- HDU 4462 Scaring the Birds (暴力枚举DFS)
题目链接:pid=4462">传送门 题意:一个n*n的区域,有m个位置是能够放稻草人的.其余都是玉米.对于每一个位置(x,y)所放稻草人都有个作用范围ri, 即abs(x-i)+ab ...
- HDU - 1248 寒冰王座 数学or暴力枚举
思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...
随机推荐
- 【Todo】RTP/RTCP/RTSP/SIP/SDP 等多媒体传输和会话协议
参考 http://m.blog.csdn.net/article/details?id=6211447
- 初探STL之算法
算法 STL算法部分主要由头文件<algorithm>,<numeric>,<functional>组成.要使用 STL中的算法函数必须包括头文件<algor ...
- Solidedge如何修改特征的参数
我已经长出了60MM,现在发现不对,要改成50MM.右击这个特征,点击编辑定义 直接左键单击尺寸,修改数据,按回车,鼠标右键,即可.
- Eclipse - 循环cin的输出怎样终止
循环cin的输出怎样终止 本文地址: http://blog.csdn.net/caroline_wendy Eclipse中, 使用CDT编写C++代码时, 循环(while)cin输入程序, 须要 ...
- Java数据结构与算法之排序
排序从大体上来讲,做了两件事情: 1.比較两个数据项: 2.交换两个数据项.或复制当中一项 一.冒泡排序 大O表示法:交换次数和比較次数都为O(N*N). 算法原理: 1.比較相邻的元素.假设第一个比 ...
- Android开发Tips(3)
欢迎Follow我的GitHub, 关注我的CSDN. 我会介绍关于Android的一些有趣的小知识点. 本文是第三篇, 其余第一篇, 第二篇. imageMogr2/auto-orient/stri ...
- ++*p,(*p)++,*p++与*++p四者的区别
四者的区别(*和++优先级相同默认从右向左运算) ++*p相当于++(*p),表示先给p指向的变量值加1,然后取该变量的值. (*p)++相当于先取p指向的变量,然后该变量值加1. *p++相当于*( ...
- passive aggressive(pa)和average perceptron(ap)
passive aggressive(pa)和average perceptron(ap)
- oracle性能监控
https://blog.csdn.net/yangshangwei/article/details/52449489#监控事例的等待 https://blog.csdn.net/yangshangw ...
- linux命令启动服务(tomcat服务或者jar包)
启动tomcat: 1.方式一:直接启动 ./startup.sh 2.方式二:nohup ./startup.sh & 启动后,关闭当前客户端连接,重新启动一个查看是 否已经启动 启动jar ...