Topcoder SRM 638 DIV 2 (大力出奇迹)

水题,就是一个暴力。大力出奇迹。

Problem Statement

  There is a narrow passage. Inside the passage there are some wolves. You are given a vector <int>
size that contains the sizes of those wolves, from left to right.

The passage is so narrow that some pairs of wolves cannot pass by each other. More precisely, two adjacent wolves may swap places if and only if the sum of their sizes is
maxSizeSum or less. Assuming that no wolves leave the passage, what is the number of different permutations of wolves in the passage? Note that two wolves are considered different even if they have the same size.

Compute and return the number of permutations of wolves that can be obtained from their initial order by swapping a pair of wolves zero or more times.

Definition

 
Class: NarrowPassage2Easy
Method: count
Parameters: vector <int>, int
Returns: int
Method signature: int count(vector <int> size, int maxSizeSum)
(be sure your method is public)

Limits

 
Time limit (s): 2.000
Memory limit (MB): 256

Constraints

- size will contain between 1 and 6 elements, inclusive.
- Each element in size will be between 1 and 1,000, inclusive.
- maxSizeSum will be between 1 and 1,000, inclusive.

Examples

0)  
 
{1, 2, 3}
3
Returns: 2
From {1, 2, 3}, you can swap 1 and 2 to get {2, 1, 3}. But you can‘t get other permutations.
1)  
 
{1, 2, 3}
1000
Returns: 6
Here you can swap any two adjacent wolves. Thus, all 3! = 6 permutations are possible.
2)  
 
{1, 2, 3}
4
Returns: 3
You can get {1, 2, 3}, {2, 1, 3} and {2, 3, 1}.
3)  
 
{1,1,1,1,1,1}
2
Returns: 720
All of these wolves are different, even though their sizes are the same. Thus, there are 6! different permutations possible.
4)  
 
{2,4,6,1,3,5}
8
Returns: 60
5)  
 
{1000}
1000
Returns: 1
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
///#define LL __int64
#define LL long long
#define INF 0x7fffffff
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?

0:x)

using namespace std;

const int maxn = 1000010;

int vis[10][10];

class NarrowPassage2Easy
{
public:
    int count(vector <int> size, int maxSizeSum)
    {
        int len = size.size();
        memset(vis, 0, sizeof(vis));
        for(int i = 1; i <= len; i++)
        {
            for(int j = i+1; j <= len; j++)
            {
                int x = size[i-1]+size[j-1];
                if(x > maxSizeSum)
                {
                    ///vis[i][j] = 1;
                    vis[j][i] = 1;
                }
            }
        }
        for(int i = 1; i <= len; i++)
        {
            for(int j = 1; j <= len; j++)
            {
                cout<<vis[i][j]<<" ";
            }
            cout<<endl;
        }
        int sum = 0;
        if(len == 1) return 1;
        if(len == 2)
        {
            if(size[0]+size[1] > maxSizeSum) return 1;
            return 2;
        }
        if(len == 3)
        {
            for(int i = 1; i <= len; i++)
            {
                for(int j = 1; j <= len; j++)
                {
                    if(i == j) continue;
                    for(int k = 1; k <= len; k++)
                    {
                        if(k == i || k == j) continue;
                        if(vis[i][j] || vis[i][k] || vis[j][k]) continue;
                        sum++;
                    }
                }
            }
        }
        if(len == 4)
        {
            for(int i1 = 1; i1 <= len; i1++)
            {
                for(int i2= 1; i2 <= len; i2++)
                {
                    if(i1 == i2) continue;
                    for(int i3 = 1; i3 <= len; i3++)
                    {
                        if(i1 == i3 || i2 == i3) continue;
                        for(int i4 = 1; i4 <= len; i4++)
                        {
                            if(i1 == i4 || i2 == i4 || i3 == i4) continue;
                            if(vis[i1][i2] || vis[i1][i3] || vis[i1][i4]
                                       || vis[i2][i3] ||vis[i2][i4]
                                       ||vis[i3][i4]) continue;
                                sum++;
                        }
                    }
                }
            }
        }
        if(len == 5)
        {
            for(int i1 = 1; i1 <= len; i1++)
            {
                for(int i2= 1; i2 <= len; i2++)
                {
                    if(i1 == i2) continue;
                    for(int i3 = 1; i3 <= len; i3++)
                    {
                        if(i1 == i3 || i2 == i3) continue;
                        for(int i4 = 1; i4 <= len; i4++)
                        {
                            if(i1 == i4 || i2 == i4 || i3 == i4) continue;
                            for(int i5 = 1; i5 <= len; i5++)
                            {
                                if(i1 == i5 || i2 == i5 || i3 == i5 || i4 == i5) continue;
                                if(vis[i1][i2] || vis[i1][i3] || vis[i1][i4] || vis[i1][i5]
                                       || vis[i2][i3] ||vis[i2][i4] || vis[i2][i5]
                                       ||vis[i3][i4] || vis[i3][i5]
                                       ||vis[i4][i5]) continue;
                                sum++;
                            }
                        }
                    }
                }
            }
        }
        if(len == 6)
        {
            for(int i1 = 1; i1 <= len; i1++)
            {
                for(int i2= 1; i2 <= len; i2++)
                {
                    if(i1 == i2) continue;
                    for(int i3 = 1; i3 <= len; i3++)
                    {
                        if(i1 == i3 || i2 == i3) continue;
                        for(int i4 = 1; i4 <= len; i4++)
                        {
                            if(i1 == i4 || i2 == i4 || i3 == i4) continue;
                            for(int i5 = 1; i5 <= len; i5++)
                            {
                                if(i1 == i5 || i2 == i5 || i3 == i5 || i4 == i5) continue;
                                for(int i6 = 1; i6 <= len; i6++)
                                {
                                    if(i1 == i6 || i2 == i6 || i3 == i6 || i4 == i6 || i6 == i5) continue;
                                    if(vis[i1][i2] || vis[i1][i3] || vis[i1][i4] || vis[i1][i5] || vis[i1][i6]
                                       || vis[i2][i3] ||vis[i2][i4] || vis[i2][i5] || vis[i2][i6]
                                       ||vis[i3][i4] || vis[i3][i5] || vis[i3][i6]
                                       ||vis[i4][i5] || vis[i4][i6]
                                       || vis[i5][i6]) continue;
                                   sum ++;
                                }
                            }
                        }
                    }
                }
            }
        }
        return sum;
    }
};
int main()
{
    NarrowPassage2Easy a;
    vector<int> f;
    f.push_back(189);
    f.push_back(266);
    cout<<a.count(f, 186)<<endl;;
    return 0;
}
时间: 2024-08-23 12:05:33

Topcoder SRM 638 DIV 2 (大力出奇迹)的相关文章

TopCoder SRM 634 Div.2[ABC]

TopCoder SRM 634 Div.2[ABC] ACM 题目地址: TopCoder SRM 634 赛后做的,感觉现场肯定做不出来Orz,简直不能多说. Level One-MountainRanges[水题] 题意: 问序列中有几个完全大于旁边的峰. 分析: 傻逼题,不多说. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: one.cpp * Create Date: 2014-09-26 21:01:23 * Desc

TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization &amp; Codeforces 839 E

传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相加,含有n个不同变量的式子的最大值. 另外限制了每一个变量的最大最小值R[i]和L[i]和所有变量之和的最大值Max. n<=13 题外话: 刚开始做这道题的时候,感觉意外眼熟? codeforces 839 E(此题的退化版):http://codeforces.com/contest/839/pro

TopCoder SRM 628 DIV 2

250-point problem Problem Statement    Janusz is learning how to play chess. He is using the standard chessboard with 8 rows and 8 columns. Both the rows and the columns are numbered 0 through 7. Thus, we can describe each cell using its two coordina

Topcoder SRM 648 (div.2)

第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. #include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #include<set> #include<map&

TopCoder SRM 596 DIV 1 250

body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } Problem Statement      You have an array with N elements. Initially, each element is 0. You can perform the following operations: Increment operation:

[topcoder]SRM 633 DIV 2

第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #include <vector> #include <algorithm> using namespace std; class Target { public: vector <string> draw(int n) { vector<string> result(n,

[topcoder]SRM 646 DIV 2

第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs.com/lautsie/p/4245242.html BFS和DFS都可以,注意的是,写的时候,可以往que里几个东西一起扔,就不用建立对象了.也可以直接用二维矩阵记录blocked和visited. 剪枝什么的,最基本的是发现其实在步数限制的情况下,棋盘就是有界的了. 第三题:http://ap

Topcoder SRM 144 DIV 1

BinaryCode 模拟 题意是:定义串P,Q,其中Q[i]=P[i-1]+P[i]+P[i+1],边界取0,并且P必须是01串.现在给你Q,让你求出P. 做法是:枚举第一位是1还是0,然后就可以推到出P[i]=Q[i-1]-P[i-1]-P[i-2],需要注意一下边界就好. Lottery 组合数学 题意是:给你四种买彩票,将他们的中奖概率排序,这四种彩票都是从1到a中取b个数字,第一种是随便取,第二种是选取的必须是有序的,第三种是选取的必须是不同的,第四种是选取的必须是有序且不同的. 做法

TopCoder SRM 639 Div.2 500 AliceGameEasy

题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数 解题思路: 首先判断n(n+1)/2 = (x+y)是否有解,即是否存在n为整数,使得所有分数的和加起来为x+y,即判断n2+n-2(x+y)=0,存在整数解, 根据二次方程的根为(-1±Δ)/2 为整数,其中Δ=√(1+8(x+y)) , 即判断1+8(x+y)是否能开方以及Δ是否为奇数(如果Δ为偶数,则根不是整数) 如果前面条件满足,在通过贪心,从