分析:是一道非常有意思的题,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. Django day 36 支付宝支付,微信推送

    一:支付宝支付, 二:微信推送

  2. 洛谷P5055 【模板】可持久化文艺平衡树(FHQ Treap)

    题面 传送门 题解 日常敲板子.jpg //minamoto #include<bits/stdc++.h> #define R register #define inline __inl ...

  3. Java多线程(五)停止线程 interrupt

    调用interrupt方法仅仅是在当前线程中打了一个停止的标记,并不是真正停止线程. this.interrupted() :测试当前线程是否已经中断,执行后具有将状态标志清除为false的功能 is ...

  4. 一个包含所有C++头文件的头函数

    #include<bits/stdc++.h> using namespace std; 使用方法和平常的头文件一样,#include<bits/stdc++.h>包含以下头文 ...

  5. CentOS6.5磁盘分区和挂载操作记录

    CentOS6.5磁盘分区和挂载操作记录. [root@CentOS ~]# fdisk -l Disk /dev/sda: bytes heads, sectors/track, cylinders ...

  6. 409 Longest Palindrome 最长回文串

    给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串.在构造过程中,请注意区分大小写.比如 "Aa" 不能当做一个回文字符串.注意:假设字符串的长度不会超过 ...

  7. [转]mysql常用函数

    转自:http://sjolzy.cn/Common-functions-mysql.html 控制流函数 IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回ex ...

  8. Kali linux 2016.2(Rolling)安装之后的常用配置

    前言 使用默认的Kali Linux设置来学习是可以的,但是我们通常要修改系统的一些基本设置,来最大化使用Kali平台的功能. 以下内容 网络的基础知识 使用图形用户界面来配置网卡 使用命令行来配置网 ...

  9. jQuery学习笔记(1)-初探

    一.jQuery是什么 1.jQuery是一套JavaScript脚本库,而不是框架:就好比"System是程序集"是类库,而"ASP.NET MVC"是框架: ...

  10. EasyUI系列学习(五)-Resizable(调整大小)

    一.创建组件 1.使用标签创建可变大小的窗口 <div id="rBox" class="easyui-resizable" style="wi ...