首页 > 其他 > 详细

UVa 1620 Lazy Susan (找规律)

时间:2016-08-01 22:50:00      阅读:550      评论:0      收藏:0      [点我收藏+]

题意:给 n 个数,每次可以把4个连续的数字翻转,问你能不能形成1-n的环状排列。

析:找一下奇偶性,写几个数试试,就会找到规律。

代码如下:

#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
using namespace std ;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-12;
const int maxn = 1e6 + 5;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
int n;
int a[505];

int main(){
    int T;  cin >> T;
    while(T--){
        scanf("%d", &n);
        int cnt = 0;
        for(int i = 0; i < n; ++i){
            scanf("%d", &a[i]);
            for(int j = 0; j < i; ++j)
                cnt += (a[i] < a[j]);
        }
        if(cnt & 1 && n & 1)  cout << "impossible\n";
        else  cout << "possible\n";
    }
    return 0;
}

 

UVa 1620 Lazy Susan (找规律)

原文:http://www.cnblogs.com/dwtfukgv/p/5727331.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!