tc srm 636 div2 500

100的数据直接暴力就行,想多了。。。

ac的代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cstdlib>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <vector>
 8 #define LL __int64
 9 const int maxn = 100+10;
10 using namespace std;
11 int a[maxn], sum;
12
13 class SortishDiv2
14 {
15 public:
16     int ways(int sortedness, vector <int> seq)
17     {
18         int f[maxn], len, i, j, ans = 0;
19         int cnt = 0, x[maxn];
20         len = seq.size();
21         memset(f, 0, sizeof(f));
22         for(i = 0; i < len; i++)
23             f[seq[i]] = 1;
24         for(i = 1; i <= len; i++)
25             if(f[i]==0)
26                 x[cnt++] = i;
27         sort(x, x+cnt);
28         do
29         {
30             int y = 0;
31             for(i = 0; i < len; i++)
32             {
33                 if(seq[i]==0) a[i] = x[y++];
34                 else a[i] = seq[i];
35             }
36             sum = 0;
37             for(i = 0; i < len; i++)
38             for(j = i+1; j < len; j++)
39             if(a[j]>a[i])
40             sum ++;
41             if(sum == sortedness) ans ++;
42         }
43         while (next_permutation(x,x+cnt));  //数字的全排列
44
45         return ans;
46     }
47 };
48
49 /*int main()
50 {
51     SortishDiv2 s;
52     int i, j, n, y, tmp;
53     vector<int>v;
54     while(1)
55     {
56         v.clear();
57         cin>>n; cin>>y;
58         for(i = 0; i < y; i++)
59         {
60           cin>>tmp;
61           v.push_back(tmp);
62         }
63         cout<<s.ways(n, v)<<endl;
64     }
65     return 0;
66 }*/
时间: 2024-10-05 06:12:42

tc srm 636 div2 500的相关文章

TC SRM 636 Div2 C ChocolateDividingHard 二分

先把行合并,然后二分一下最小值就好. // BEGIN CUT HERE // END CUT HERE #line 5 "ChocolateDividingHard.cpp" #include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include

Topcoder SRM 619 DIv2 500 --又是耻辱的一题

这题明明是一个简单的类似约瑟夫环的问题,但是由于细节问题迟迟不能得到正确结果,结果比赛完几分钟才改对..耻辱. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define ll long long using namespace std; #define NN 370000 class Choo

TC SRM 665 DIV2 A LuckyXor 暴力

LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive integer consisting of only the digits 4 and 7.Given an int a, return an int b strictly greater than a, such that a XOR b is a lucky number. (See Notes fo

TC SRM 664 div2 B BearPlaysDiv2 bfs

BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by moving some stones between three piles of stones. Initially, the piles contain A, B, and C stones, respectively. Limak's goal is to produce three equa

TC SRM 663 div2 A ChessFloor 暴力

ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a square room. The floor of the room is an N times N grid of unit square tiles. Each tile has some color. You are given the current colors of all tiles in a

TC SRM 663 div2 B AABB 逆推

AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many English words only use the letters A and B. Examples of such words include "AB" (short for abdominal), "BAA" (the noise a sheep makes), &

TC SRM 664 div2 AB

#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; class BearCheats{ public: string eyesight(int A, int B){ char t[256]; string s1; sprintf(t, "%d", A); s1 = t; string s2; cha

TC SRM 637 DIV1 500 PathGame

Problem Statement 给一个2*1000的board,每个格子黑或者白.白格子从左到右连成一条连接第一列和最后一列的path,path上相邻两格有公共边.两人轮流把白格子涂成黑格子,最后一个被迫涂黑格子使path断开的人输.问先手必胜还是必败. (Translated By myq_952) Tutorial 做sg的题有点生(有什么生不生的不就dp嘛) 考虑以一段2*k的全白矩形作为局面,涂黑一个格子会把原局面拆成两个后继局面,然后$n^2$求局面的sg即可 要注意的是,因为本题

TC SRM 670 div2 Treestart

题目大意: 一个树状的棋盘,A,B两种棋子.初始时没有棋子重合,每一轮AB轮流移动任意个(包括不移动)自己的棋子,可以重合.如果某一时刻一格子上同时存在A和B两种棋子,则B获胜.A尽量使游戏进行的总轮数最多,B尽量在最少的轮数获胜(B 一定能获胜),输出最少轮数. 解题思路: 单独考虑A的每个棋子,每次分别扩展并跟新A和B能到的格子,如果A能到的格子中没有B不能到的,那么B胜利. 由于只有50个点,可以用状态压缩来让代码变得更加优美一点~! using namespace std; vector