分析:是一道非常有意思的题,30分的暴力的话枚举每个位置是什么数,然后排个序,用map判一下重就好了,比较麻烦.

满分做法显然不可能讨论每个位置所有的情况,肯定是有规律的,现将这n*(n-1)/2个数排序,假设N个数组成的排列是a1,a2,......,aN,并且a1≤a2≤......≤aN.那么最小的那个和肯定是a1 + a2,次小的那个和肯定是a1 + a3,第三小的就不好确定了,如果能把a2 + a3给求出来,那么就能把a1,a2,a3给解出来,所以枚举a2+a3是哪一个,把a1+a2,a2+a3,a1+a3给求出来后从原数组中删掉,那么剩下的最小的数就是a1+a4,a4可以解出来,再把a2,a3与a4相加,把得到的数给删掉,再对a5进行同样的操作,就能得到整个序列了,所以枚举a2+a3的位置,并check一下就好了.

check的时候要先判断这个ai+a1在原数组中存不存在,是否都已经被占用了,要判断好所有的情况才行.

30分暴力:

#include <cstdio>
#include <map>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, cnt, a[], flag[], ans,tot,tag[];
int p[],cnt2,anss[][]; map<long long,bool> vis; struct node
{
int a[];
node() { memset(a, , sizeof(a)); }
}e[]; bool cmp(node x,node y)
{
for (int i = ; i <= n; i++)
if (x.a[i] > y.a[i])
return ;
return ;
} void print()
{
for (int i = ; i <= n; i++)
printf("%d ", flag[i]);
printf("\n");
} void solve()
{
long long res = ;
//print();
memcpy(tag,flag,sizeof(flag));
sort(tag + ,tag + + n);
for (int i = ; i <= n; i++)
res = (res * + tag[i]);
if (vis[res])
return;
vis[res] = ;
cnt2 = ;
for (int i = ; i <= n; i++)
for (int j = ; j < i; j++)
p[++cnt2] = flag[i] + flag[j];
sort(p + , p + + cnt2);
for (int i = ; i <= cnt; i++)
if (p[i] != a[i])
return;
tot++;
for (int i = ; i <= n; i++)
e[tot].a[i] = tag[i];
ans++;
} void dfs(int dep)
{
if (dep == n + )
{
solve();
return;
}
for (int i = ; i >= ; i--)
{
flag[dep] = i;
dfs(dep + );
}
} int main()
{
scanf("%d", &n);
cnt = n * (n - ) / ;
for (int i = ; i <= cnt; i++)
scanf("%d", &a[i]);
sort(a + ,a + + cnt);
dfs();
printf("%d\n", ans);
sort(e + ,e + + tot,cmp);
for (int i = ; i <= tot; i++)
{
for (int j = ; j <= n; j++)
printf("%d ", e[i].a[j]);
printf("\n");
} return ;
}

正解:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm> using namespace std; int n, a[], cnt, tot, ans[][], val[];
bool vis[]; void solve(int x)
{
memset(vis, , sizeof(vis));
int temp = (a[] + a[] + a[x]) / ;
val[] = temp - a[];
val[] = temp - a[];
val[] = temp - a[x];
vis[] = vis[] = vis[x] = ;
int cur = ;
for (int i = ; i <= n; i++)
{
while (cur <= cnt && vis[cur])
cur++;
if (cur > cnt)
return;
val[i] = a[cur] - val[];
vis[cur] = ;
for (int j = ; j < i; j++)
{
if (val[j] > val[i])
return;
int v = val[j] + val[i];
int pos = lower_bound(a + , a + cnt + , v) - a;
if (a[pos] != v)
return;
int pos2 = pos;
while (pos2 && a[pos2] == a[pos])
pos2--;
pos2++;
while (pos2 <= cnt && a[pos2] == a[pos] && vis[pos2])
pos2++;
if (a[pos2] != a[pos] || vis[pos2])
return;
vis[pos2] = ;
}
}
++tot;
for (int i = ; i <= n; i++)
ans[tot][i] = val[i];
} int main()
{
scanf("%d", &n);
cnt = n * (n - ) / ;
for (int i = ; i <= cnt; i++)
scanf("%d", &a[i]);
sort(a + , a + + cnt);
for (int i = ; i <= cnt; )
{
solve(i);
int j = i;
while (j <= cnt && a[j] == a[i])
j++;
i = j;
}
printf("%d\n", tot);
for (int i = ; i <= tot; i++)
{
for (int j = ; j <= n; j++)
printf("%d ", ans[i][j]);
printf("\n");
} return ;
}

noip模拟赛 都市的更多相关文章

  1. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  2. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  3. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  4. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  5. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  6. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  7. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  8. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  9. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

随机推荐

  1. 最常用的~正则表达式-相关js函数知识简洁分享【新手推荐】

    一.正则表达式的创建 JS正则的创建有两种方式: new RegExp() 和 直接字面量. //使用RegExp对象创建 varregObj =newRegExp("(^\s+)|(\s+ ...

  2. bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级【分层图+spfa】

    至死不用dijskstra系列2333,洛谷上T了一个点,开了O2才过 基本想法是建立分层图,就是建k+1层原图,然后相邻两层之间把原图的边在上一层的起点与下一层的终点连起来,边权为0,表示免了这条边 ...

  3. 2017杭电多校第五场11Rikka with Competition

    Rikka with Competition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  4. web api 二

    接着上一回说,上回说到,web api有几种访问方式,具体有几种,我还真没去研究过,但是这里打算从get.post.put.delete四种请求方式分别谈谈基础类型(包括int/string/date ...

  5. Android4.4以上Uri转换成绝对路径的工具类

    一.Android4.4版本以上Uri地址封装规范: content://com.android.providers.media.documents/document/image%3A659 二.An ...

  6. redis之有序集合类型(Zset)——排行榜的实现

    当数据库对排序支持的不是很好,可以利用redis有序集合排序 原文链接:http://blog.csdn.net/loophome/article/details/50373202

  7. FCC 基础JavaScript 练习6

    1.对象和数组很相似,数组是通过索引来访问和修改数据,对象是通过属性来访问和修改数据的, 对象适合用来存储结构化数据,就和真实世界的对象一模一样,比如一只猫. 任务 创建一个叫做myDog的对象,它里 ...

  8. IT项目为什么失败 --美国IT项目管理硕士笔记(一)

    IT项目为什么失败 什么是项目   项目可以被看作任何一系列的活动和任务.这些活动和任务有一个特定目标需要在特定要求下完成,并有一个明确的开始结束日期和资金限制(如果有).项目需要消耗人力或非人力资源 ...

  9. nodejs——避免判断创建多级目录

    基本概念 fs.exists已经弃用,可以使用fs.access判断文件夹是否存在,但是官方的建议是在进行文件操作前不要使用fs.access,官方推荐的方式的是直接进行文件操作,有错误再修改 不建议 ...

  10. 328.io流(字符串-练习-复制文本文件一)

    public static void main(String[] args) { // TODO Auto-generated method stub FileReader fr = null; Fi ...