分析:是一道非常有意思的题,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[20], flag[20], ans,tot,tag[20];
int p[20],cnt2,anss[100010][7];map<long long,bool> vis;struct node
{int a[12];node()  { memset(a, 0, sizeof(a)); }
}e[10010];bool cmp(node x,node y)
{for (int i = 1; i <= n; i++)if (x.a[i] > y.a[i])return 1;return 0;
}void print()
{for (int i = 1; i <= n; i++)printf("%d ", flag[i]);printf("\n");
}void solve()
{long long res = 0;//print();memcpy(tag,flag,sizeof(flag));sort(tag + 1,tag + 1 + n);for (int i = 1; i <= n; i++)res = (res * 10 + tag[i]);if (vis[res])return;vis[res] = 1;cnt2 = 0;for (int i = 2; i <= n; i++)for (int j = 1; j < i; j++)p[++cnt2] = flag[i] + flag[j];sort(p + 1, p + 1 + cnt2);for (int i = 1; i <= cnt; i++)if (p[i] != a[i])return;tot++;for (int i = 1; i <= n; i++)e[tot].a[i] = tag[i];ans++;
}void dfs(int dep)
{if (dep == n + 1){solve();return;}for (int i = 10; i >= 1; i--){flag[dep] = i;dfs(dep + 1);}
}int main()
{scanf("%d", &n);cnt = n * (n - 1) / 2;for (int i = 1; i <= cnt; i++)scanf("%d", &a[i]);sort(a + 1,a + 1 + cnt);dfs(1);printf("%d\n", ans);sort(e + 1,e + 1 + tot,cmp);for (int i = 1; i <= tot; i++){for (int j = 1; j <= n; j++)printf("%d ", e[i].a[j]);printf("\n");}return 0;
}

正解:

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

转载于:https://www.cnblogs.com/zbtrs/p/7764349.html

noip模拟赛 都市相关推荐

  1. NOI.AC NOIP模拟赛 第六场 游记

    NOI.AC NOIP模拟赛 第六场 游记 queen 题目大意: 在一个\(n\times n(n\le10^5)\)的棋盘上,放有\(m(m\le10^5)\)个皇后,其中每一个皇后都可以向上.下 ...

  2. 【noip模拟赛4】Matrix67的派对 暴力dfs

    [noip模拟赛4]Matrix67的派对 描述 Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们安排 ...

  3. 【HHHOJ】NOIP模拟赛 捌 解题报告

    点此进入比赛 得分: \(30+30+70=130\)(弱爆了) 排名: \(Rank\ 22\) \(Rating\):\(-31\) \(T1\):[HHHOJ260]「NOIP模拟赛 捌」Dig ...

  4. jyzy noip模拟赛5.22-2

    不知道哪来的题 jyzy noip模拟赛5.22-2 样例输入 1 2 3 4 样例输出 0.200000000000000 数据 |a|,|b|,|c|,|d|<=1e9 很多大佬迅速想到二分 ...

  5. NOIP模拟赛csy2021/10/30

    NOIP模拟赛csy2021/10/30 比赛时间规划 赛后反思与总结 这..总的来说感觉打的很不好,根本没有状态,有一部分原因是今天来晚了,太慌,更多的还是这次题感觉很难o(╥﹏╥)o 比赛时间规划 ...

  6. 【WZOI第二次NOIP模拟赛Day1T2】世界末日 解题报告

    [WZOI第二次NOIP模拟赛Day1T2]世界末日 Problem 2 世界末日 (doomsday.pas/c/cpp) 背景 话说CWQ大牛终于打开了那扇神秘大门,但迎接他的不是什么神秘的东西, ...

  7. NOIP 模拟赛 长寿花 题解

    NOIP 模拟赛 长寿花 题解 要放 \(n\) 层物品,第 \(i\) 层有 \(a_i\) 个位置放物品,物品有 \(m\) 中颜色,有约束条件: 同一层两个相邻物品颜色不能相同. 相邻两层颜色集 ...

  8. 辣鸡(ljh) NOIP模拟赛 模拟 平面几何 数论 化学相关(雾)

    [题目描述] 辣鸡ljhNOI之后就退役了,然后就滚去学文化课了. 然而在上化学课的时候,数学和化学都不好的ljh却被一道简单题难住了,受到了大佬的嘲笑. 题目描述是这样的:在一个二维平面上有一层水分 ...

  9. NOIP模拟赛套路技巧经验总结

    前言 还有2天就NOIP了,之前做了这么多场模拟赛,是时候拿出来总结一下, 算是给自己一针强心剂. 列表 从最近的考试总结起(个人认为的重点,可能有重复,仅供参考): (转化很重要,一定要简化问题过后 ...

最新文章

  1. flask_sqlalchemy 中 or 、 and 和 like 的用法
  2. 设计师学习HTML/CSS之路-01
  3. 基于OSS存储搭建Hadoop集群
  4. 007_Buzz事件
  5. python if name main 的作用_Python中if __name__ == __main__: 的作用
  6. pythondocumentation是什么_怎样阅读Python官方文档
  7. MapReduce计数器
  8. hadoop tyarn冲突_Doris与Hadoop yarn混合部署遇到的坑
  9. 视频直播 > 最佳实践 > 如何降低延时
  10. Runtime Library
  11. Android Studio AVD中文输入法安装
  12. 【Java】第6章 访问权限控制
  13. markdown删除代码空白行
  14. 战国七雄中最强大的国家(除秦外)——赵国_我是亲民_新浪博客
  15. MapReducer Counter计数器的使用,Combiner ,Partitioner,Sort,Grop的使用,
  16. ThinkPhP关联查询setEagerlyType遇到的问题
  17. ent orm笔记2---schema使用(上)
  18. iPhone屏幕旋转机制详解
  19. 第1章第17节:如何使用备注功能对内容进行注释补充 [PowerPoint精美幻灯片实战教程]
  20. 切断ADG的关联,划分为两个独立的数据库

热门文章

  1. 第一次在Django上编写静态网页
  2. 逗比学树莓派之GPIO
  3. Spring--Quartz 任务调度的配置详解
  4. 对PostgreSQL源代码中的build_jion_rel的理解
  5. 面向接口编程 (噬菌体) 不错的接口
  6. 重新拾起VS2008加入战斗
  7. Google CVPR 2019最新成果!用神经架构搜索实现更好的目标检测
  8. 最受欢迎中文机器学习课程,台大李宏毅老师公开课2019版上线!
  9. ACM MM2021 | 快手获得Grand Challenge第一名
  10. Linux | Ubuntu:十年,十个关键时刻