UVa 1620 Lazy Susan (找规律)

题意:给 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;
}
时间: 2024-08-04 13:58:36

UVa 1620 Lazy Susan (找规律)的相关文章

UVa 12627 (递归 计数 找规律) Erratic Expansion

直接说几个比较明显的规律吧. k个小时以后,红气球的个数为3k. 单独观察一行: 令f(r, k)为k个小时后第r行红气球的个数. 如果r为奇数,f(r, k) = f((r+1)/2, k-1) * 2 如果r为偶数,f(r, k) = f(r/2, k-1) 令g(r, k)为k个小时后前r行红气球的个数. 如果r为偶数,g(r, k) = g(r/2, k-1) * 3; 如果r为奇数,g(r, k) = g(r-1, k) + f(r, k); 因此f和g都可以用递归求解. 1 #inc

UVA 1363 Joseph&#39;s Problem 找规律+推导 给定n,k;求k%[1,n]的和。

/** 题目:Joseph's Problem 链接:https://vjudge.net/problem/UVA-1363 题意:给定n,k;求k%[1,n]的和. 思路: 没想出来,看了lrj的想法才明白. 我一开始往素数筛那种类似做法想. 想k%[1,n]的结果会有很多重复的,来想办法优化. 但没走通. 果然要往深处想. 通过观察数据发现有等差数列.直接观察很难确定具体规律:此处应该想到用式子往这个方向推导试一试. lrj想法: 设:p = k/i; 则:k%i = k-i*p; 容易想到

(白书训练计划)UVa 12627 Erratic Expansion(递归+找规律)

题目地址:UVa 12627 这题是先找规律,规律在于对于第k个小时的来说,总是可以分成右下角全是蓝色气球,右上角,左下角与左上角三个一模一样的k-1个小时的气球.这样的话,规律就很清晰了,然后用递归做比较方便... 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <ma

UVA - 11384 - Help is needed for Dexter (找规律!!)

UVA - 11384 Help is needed for Dexter Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem H Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee Dee b

递推+高精度+找规律 UVA 10254 The Priest Mathematician

题目传送门 1 /* 2 题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数 3 递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子,2 ^ (n - k) - 1 4 所以f[n] = min (f[k] * 2 + g[n-k]),n<=10000,所要要用高精度,另外打表能看出规律 5 */ 6 /************************************************ 7 * Auth

【UVA】11040 - Add bricks in the wall(找规律)

一道找规律的题,可以看出,大的三角形可以划分成好多个三层的三角形: [x] [a][x-a] [y] [    ][z] 这里面xyz都已知,所以可以求出a = (x + y - z ) /2 14043615 11040 Add bricks in the wall Accepted C++ 0.019 2014-08-15 06:02:50 #include<cstdio> #include<cstring> #include<iostream> #include&

UVA - 1646 - Edge Case(找规律)

题意:n(3 <= n <= 10000)个结点组成一个圈,求匹配(即没有公共点的边集)的个数. 找规律为斐波那契的性质,因为数太大所以用的java大数. import java.math.BigInteger; import java.util.Scanner; public class Main{ public static int MAXN = 10000 + 10; public static BigInteger []c = new BigInteger[MAXN]; public

UVA 11774 - Doom&#39;s Day(规律)

UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,如下: We can associate at each cell a base 3-number, the log3(R) most significant digits is the index of the row of the cell

hdoj 1097 A hard puzzle (找规律)

A hard puzzle                            T   ime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29231    Accepted Submission(s): 10494 Problem Description lcy gives a hard puzzle to feng5166,lwg,JG