# Codeforces Round Rockethon 2015

A. Game

``` 1 #include<iostream>
2 #include<cstdio>
3 #include <math.h>
4 #include<algorithm>
5 #include<string.h>
6 #include<queue>
7 #define MOD 10000007
8 #define maxn 200000
9 #define LL long long
10 using namespace std;
11 int main()
12 {
13         int a,b,c,d;
14         scanf("%d%d%d%d",&a,&b,&c,&d);
15         if(a<=b)printf("Second\n");else printf("First\n");
16         return 0;
17 }```

B. Permutations

``` 1 #include<iostream>
2 #include<cstdio>
3 #include <math.h>
4 #include<algorithm>
5 #include<string.h>
6 #include<queue>
7 #define MOD 10000007
8 #define maxn 200000
9 #define LL long long
10 using namespace std;
11 long long bin[100];
12 int visit[maxn],ans[maxn];
13 int main()
14 {
15         bin[0]=1;
16         for(int i=1;i<=51;i++)bin[i]=bin[i-1]*2LL;
17         int n,anss;
18         long long m;
19         while(scanf("%d%I64d",&n,&m)!=EOF)
20         {
21                 int last=n;
22                 for(int i=1,j=1;i<=n;i++)
23                 {
24                         int u=bin[n-i-1];
25                         if(m<=u)ans[j]=i,j++;
26                         else ans[last]=i,last--,m-=u;
27                 }
28                 for(int i=1;i<=n;i++)printf("%d ",ans[i]);
29         }
30         return 0;
31 }```

G1:Inversions problem

``` 1 #include<iostream>
2 #include<cstdio>
3 #include <math.h>
4 #include<algorithm>
5 #include<string.h>
6 #include<queue>
7 #define MOD 10000007
8 #define maxn 200000
9 #define LL long long
10 using namespace std;
11 int a[100],m,n,up=0,down=0;
12 void dfs(int kk,int b[])
13 {
14         int c[100],d[100];
15         memcpy(d,b,sizeof(d));
16         if(kk==m+1)
17         {
18                 int inv=0;
19                 for(int i=1;i<=n;i++)
20                 {
21                         for(int j=i+1;j<=n;j++)
22                         {
23                                 if(b[j]<b[i])inv++;
24                         }
25                 }
26                 up+=inv;down++;
27                 return;
28         }
29         for(int i=1;i<=n;i++)
30                 for(int j=i;j<=n;j++)
31                 {
32                         for(int k=1;k<=j-i+1;k++)
33                         {
34                                 c[k]=b[j-k+1];
35                         }
36                         for(int k=1;k<=j-i+1;k++)
37                         {
38                                 b[i+k-1]=c[k];
39                         }
40                         dfs(kk+1,b);
41                         for(int k=1;k<=j-i+1;k++)
42                         {
43                                 c[k]=b[j-k+1];
44                         }
45                         for(int k=1;k<=j-i+1;k++)
46                         {
47                                 b[i+k-1]=c[k];
48                         }
49                 }
50 }
51 int main()
52 {
53         scanf("%d%d",&n,&m);
54         for(int i=1;i<=n;i++)
55         {
56                 scanf("%d",&a[i]);
57         }
58         dfs(1,a);
59         printf("%.9lf",1.0*up/down);
60         return 0;
61 }```

## Codeforces Round #290 (Div. 2) b

/** * @brief Codeforces Round #290 (Div. 2) b * @file a.cpp * @author mianma * @created 2015/02/04 15:17 * @edited 2015/02/04 15:17 * @type brute * @note */ #include <fstream> #include <iostream> #include <string> #include <cstring>

## Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

## Codeforces Round #400 C 前缀和,思维

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals 题意:n个数,问有多少个区间的和是k的次方数,即sum([l, r])=k^x, x>=0. abs(k)<=10. tags:一开始O(n^2)统计,果然炸了.. 这题要在统计到第 i 个数时,看s[i]-k^x是否在前面出现过.因为k指数增长很快,这样就是O(n). // #400 #include<b

## Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

## Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f