分析:是一道非常有意思的题,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. 洛谷 P3121 [USACO15FEB]审查(黄金)Censoring (Gold) 【AC自动机+栈】

    这个和bzoj同名题不一样,有多个匹配串 但是思路是一样的,写个AC自动机,同样是开两个栈,一个存字符,一个存当前点在trie树上的位置,然后如果到了某个匹配串的末尾,则弹栈 #include< ...

  2. java 并发编程 Executor框架

    http://blog.csdn.net/chenchaofuck1/article/details/51606224 demo package executor; import java.util. ...

  3. 递推DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...

  4. ViewPager(4)用viewpager实现splash view

    1,示例 2,代码 SplashMain.java import android.os.Bundle; import android.support.v4.app.Fragment; import a ...

  5. 368 Largest Divisible Subset 最大整除子集

    给出一个由无重复的正整数组成的集合, 找出其中最大的整除子集, 子集中任意一对 (Si, Sj) 都要满足: Si % Sj = 0 或 Sj % Si = 0.如果有多个目标子集,返回其中任何一个均 ...

  6. YumRepo Error: All mirror URLs are not using ftp, http[s] or file

    有台机器使用Yum的时候,报错如下: YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. $releaseve ...

  7. Android RecyclerView局部刷新那个坑

    关键:public final void notifyItemChanged(int position, Object payload) RecyclerView局部刷新大家都遇到过,有时候还说会遇见 ...

  8. CNN:测试一下YoloV3

    项目地址:https://pjreddie.com/darknet/yolo/ mAP提升了不少,在VS上试一把 V3 的权值: https://pjreddie.com/media/files/yo ...

  9. Think PHP中URL_MODE相关事项

    官网上有关于URL_MODE的解释:http://document.thinkphp.cn/manual_3_2.html#url 这里主要讲一下URL_MODE为2,即REWRITE模式. REWR ...

  10. x86汇编之十(使用字符串)

    x86汇编之十(使用字符串) 转自网络,出处不详 一.传送字符串 Intel提供了完整的字符串传送指令,就像是MOV指令一样. 1.MOVS指令 1)movs指令格式 把字符串从一个位内存位置传送到另 ...