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的 ...
随机推荐
- [转] twemproxy ketama一致性hash分析
评注:提到HAProxy业务层proxy, twemproxy存储的proxy. 其中还提到了ketama算法的实现源码 转自:http://www.cnblogs.com/basecn/p/4288 ...
- C++中结构和类的区别
首先从从语言角度来看,c语言是一种结构化的语言,便于按照模块化的方式来组织程序,易于程序员的调试和维护,而对于c++来说,我么可以认为它是标准c的超集.实际上所有的c程序也是c++程序.但两者之间还是 ...
- MySQL和MongoDB的性能测试
软硬件环境 MySQL版本:5.1.50,驱动版本:5.1.6(最新的5.1.13有很多杂七杂八的问题) MongoDB版本:1.6.2,驱动版本:2.1 操作系统:Windows XP SP3(这个 ...
- 【转载】C#扫盲之:静态成员、静态方法、静态类、实例成员及区别
文章目录 1.静态成员.实例成员 2.静态类 3.类的静态成员和非静态成员区别 --------------------------------------分割线------------------- ...
- [转载]php 数组 类对象 值传递 引用传递 区别
一般的数据类型(int, float, bool)不做这方面的解说了 这里详细介绍一下数组和的类的对象作为参数进行值传递的区别 数组值传递 实例代码: <?php function main() ...
- 《Unix网络编程》中的错误处理函数
#include "net.h" #include <syslog.h> // syslog() int daemon_proc; static void err_do ...
- 软件版本号(BETA、RC、ALPHA、Release、GA等)
Alpha: Alpha是内部测试版,一般不向外部发布,会有很多Bug.除非你也是测试人员,否则不建议使用.是希腊字母的第一位,表示最初级的版本,alpha 就是α,beta 就是β , ...
- device not managed by NetworkManager
Bringing up interface eth0:Error:Connection activation failed:Device not managed by NetworkManager ...
- 简单的dp hdu 数塔(水题)
数塔 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- 解决asp.net mvc UpdateModel更新对象后出现null问题的方法
在用asp.net mvc 4.0做项目的时候遇到的这种情况:情况分析:“在填写表单的时候,有一些表单没有填写,留空,然后直接post 提交表单,action中用UpdateModel 来更新mode ...