分析:是一道非常有意思的题,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. 慕课网4-2 编程练习:jQuery祖先后代选择器小案例

    4-2 编程练习 结合所学的祖先后代选择器,实现如下图所示效果 任务 (1)使用祖先后代选择器将第二段文字背景色变成红色 (2)使用jQuery的.css()方法设置样式,语法css('属性 '属性值 ...

  2. redis之简单动态字符串(SDS)

    O(N):时间复杂度 N的值越大 时间复杂度随N的平方增大 O(1):就是说N很大的时候,复杂度基本不增长了.基本就是常量了. 在Redis数据库里 包含字符串值的键值对 在底层都是由SDS实现的. ...

  3. 公司4:JrVue主题定制

    JrVue是我们基于element重新封装的一套组件库;  具体组件使用方法可以mnote->研发小组查看; 这里我们定制了一套主题色, 具体变动如下: 1.主题色变动: mfront有蓝.紫. ...

  4. Java多线程(一) Thread和 Runnable

    http://www.cnblogs.com/lwbqqyumidi/p/3804883.html 1.继承Thread 2.实现Runnable接口 public class MyRunnable ...

  5. 【NOIP模拟赛】一道挖掉背景的数学题

    Title:[Empty] Time Limit:1000 ms Memory Limit:131072 KBytes Description 给定n与p,求\(\left\lfloor x^n\ri ...

  6. 在 NodeJs 上搭建 React 开发环境

    步骤: 1. 安装 nodejs :根据你的 Windows 类型(x86或x64)下载相应的安装包进行安装.安装完成后,可以在任一目录下打开 cmd 窗口并运行 node -v 命令,如果显示 no ...

  7. html5前端杂记

    首先是css的一些知识 毕竟自己懂得不多,但是一看资料.感觉似曾相识 <style> .red-text { color: red; } </style>//这里是css样式的 ...

  8. LR接口测试---基于http协议之get/post

    get请求代码: //=====================get interface======================== 以http状态码方式: //获取返回的HTTP状态码判断请求 ...

  9. Android基础TOP6_2:Gallery +Image完成画廊

    Activity: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  10. swing jTable排序问题(点击表头排序)

    1.JDK6自带排序实现: tableName.setAutoCreateRowSorter(true); 2.其实界面设计中勾选一个属性就搞定了: .