题意:...

析:我们可以知道,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 小希的数表 (暴力枚举+数学)的更多相关文章

  1. hdu 1270 小希的数表

    思路:一定有sum[1]=num[1]+num[2],sum[2]=num[1]+num[3]; 但是sum[3]不知道是由num[1]+num[4]还是num[2]+num[3],这就需要枚举一下了 ...

  2. hdu 1172 猜数字(暴力枚举)

    题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...

  3. hdu 4445 Crazy Tank (暴力枚举)

    Crazy Tank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  5. HDU 4930 Fighting the Landlords(暴力枚举+模拟)

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

  6. HDU 4431 Mahjong (DFS,暴力枚举,剪枝)

    题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...

  7. hdu 5491 The Next(暴力枚举)

    Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...

  8. HDU 4462 Scaring the Birds (暴力枚举DFS)

    题目链接:pid=4462">传送门 题意:一个n*n的区域,有m个位置是能够放稻草人的.其余都是玉米.对于每一个位置(x,y)所放稻草人都有个作用范围ri, 即abs(x-i)+ab ...

  9. HDU - 1248 寒冰王座 数学or暴力枚举

    思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...

随机推荐

  1. bootstrap -- col-sm-6 和 col-xs-6

  2. HDU - 4630 No Pain No Game (线段树 + 离线处理)

    id=45786" style="color:blue; text-decoration:none">HDU - 4630 id=45786" style ...

  3. 软件系统架构 https://www.lanhusoft.com/Article/349.html

    跟蓝狐学习Nop--NopCommerce源码架构详解专题目录 Posted By : 蓝狐 Updated On : 2018-04-16 14:46 我们承接以下nop相关的业务,欢迎联系我们. ...

  4. aip接口中对url参数md5加密防篡改的原理

    目前网上所有开放api的网站中,数据的调用都是采用同一种方式,即: http:www.xxx.com/aa=1&bb=2...,原后对这些参数按字典顺序排序后进行md5加密,将md5加密串与接 ...

  5. 远程连接mysql速度慢的解决方法:skip-name-resolve取消DNS的反向解析

    PHP远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的 MYSQL开启了DNS的反向解析,在MY.INI(WINDOW ...

  6. 细谈SetButtonInfo函数及其用途

    SetButtonInfo用于设置某个按钮,它的接口定义如下: 下面是它的几个接口函数说明: void CToolBar::SetButtonInfo(int nIndex, UINT nID, UI ...

  7. AptitudeSystem 2.0

    AptitudeSystem 2.0(2017-03-07) 描写叙述:Windows内核研究辅助工具 支持的系统:Windows 7.Windows 8.Windows 8.1.Windows 10 ...

  8. Xcode6.1 Prefix.pch添加方式

     本文转载:http://blog.csdn.net/foolsong/article/details/40653497     在Xcode6.1中创建工程默认是没有Prefix.pch文件的,需要 ...

  9. 基于第三方微信授权登录的iOS代码分析

    本文转载至 http://www.cocoachina.com/ios/20140922/9715.html 微信已经深入到每一个APP的缝隙,最常用的莫过分享和登录了,接下来就以代码的形式来展开微信 ...

  10. COGS28 [NOI2006] 最大获利[最大权闭合子图]

    [NOI2006] 最大获利 ★★★☆   输入文件:profit.in   输出文件:profit.out   简单对比时间限制:2 s   内存限制:512 MB [问题描述] 新的技术正冲击着手 ...