codeforces194a

August 15, 2013
CodeForces

link:http://codeforces.com/contest/334/problem/A 很有意思的一道构造题。发现CF上经常出这种不难但是很不错的构造题。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[8][2] = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1}};
using namespace std;
int main(void)
{
    int n;
    while (~scanf("%d",&n))
    for (int i=1;i<=n*n/2;++i)
    {
        for (int j=1;j<=n/2;++j)
        {
            printf("%d %d ",i,n*n-i+1);
            ++i;
        }
        i--;
        printf("\n");
    }
    return 0;
}

o(╯□╰)o 官方解题报告上面写的很明白 1  n^2 2  n^2-1 ..  .. n^2/2  n^22+1 然后这就是n^2/2组,每一组的和都相同。n^2/2/(n/2) = n组,所以我们只需要从这n^2/2组里面选择n/2组就满足了一个解,这样,恰好可以选出n组来。

comments powered by Disqus