1 /*
2 - 最开始用全排列
3 - 突然发现有13位, 但是只用了12位
4 - ......
5 - 可能只能搜索了, 这里我想深搜似乎可以做...吧
6 */
7 #include<iostream>
8 #include<cstring>
9 #include<string>
10 #include<algorithm>
11
12 using namespace std;
13
14 // int a[14] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
15 int t[14] = {0};
16 bool book[14];
17 long long s = 0;
18
19 bool judge(int k)
20 { // cout<<"JUDGE"<<'\n';
21 switch(k)
22 {
23 case 3:{
24 return t[1] + t[2] == t[3];
25 break;
26 }
27 case 6:{
28 return t[4] - t[5] == t[6];
29 break;
30 }
31 case 9:{
32 return t[7] * t[8] == t[9];
33 break;
34 }
35 case 12:{ // 这里注意一下万一出现浮点数了呢~ 所以要移项变号
36 return t[12]*t[11] == t[10];
37 printf("%d -- %d -- %d\n", t[1], t[2], t[3]);
38 printf("%d -- %d -- %d\n", t[4], t[5], t[6]);
39 printf("%d -- %d -- %d\n", t[7], t[8], t[9]);
40 printf("%d -- %d -- %d\n", t[10], t[11], t[12]);
41 s++;
42 break;
43 }
44 default:return false;break;
45 }
46 }
47
48 void DFS(int n)
49 { // 每填完三个数就判断, 回溯剪枝
50 if(n == 13) return;
51 for(int i=1;i<14;i++){
52 if(book[i]) // 访问过
53 continue;
54 t[n] = i;
55 book[i] = true;
56 if(n%3 == 0 && !judge(n)){ // 条件不符合
57 book[i] = false;
58 continue;
59 }
60 DFS(n+1);
61 book[i] = false;
62 }
63 return;
64 }
65
66 int main()
67 {
68 memset(t, 0, sizeof(t));
69 memset(book, false, sizeof(book));
70
71 DFS(1);
72
73 cout<<s<<'\n';
74
75 return 0;
76 }
77
78 /*
79 while(next_permutation(a+1, a+14))
80 {
81 if(a[1] + a[2] != a[3])
82 continue;
83 if(a[4] - a[5] != a[6])
84 continue;
85 if(a[7] * a[8] != a[9])
86 continue;
87 if(a[11]*a[12] != a[10])
88 continue;
89 s++;
90 }
91 cout<<s<<'\n';
92 */
1 /*
2 * 加法变乘法
3 */
4 #include<iostream>
5 #include<cstring>
6 #include<string>
7 #include<algorithm>
8
9 using namespace std;
10
11 const int z = 2015;
12 int s = 1225;
13
14 int main()
15 {
16 /*
17 for(int i=1;i<47;i++){
18 for(int j=3;j<49;j++){
19 int x = i*(i+1);
20 int y = j*(j+1);
21 if(s + x + y - i - (i+1) - j - (j+1) == z){
22 cout<<i<<'\n';
23 }
24 }
25 }
26 */
27 cout<<16<<'\n';
28 return 0;
29 }
30 /*
31 10
32 16
33 24
34 27
35 */
1 #include<iostream>
2 #include<cstring>
3 #include<string>
4 #include<algorithm>
5
6 using namespace std;
7
8 int t[15] = {0};
9
10 // 万能的搜索
11 void DFS(int n)
12 {
13 if(n == 4) DFS(n+1);
14 if(n == 7){
15 for(int i=1;i<=14;i++)
16 cout<<t[i];
17 cout<<'\n';
18 return;
19 }
20 for(int i=1;i<=14;i++){
21 if(i == 1 || i == 2 || i == 9 || i == 7)
22 continue; // 已经就位
23 int loc = i+n+1;
24 if(loc > 14) continue; // 边界
25 if(t[i] == 0 && t[loc] == 0){
26 t[i] = t[loc] = n;
27 DFS(n+1);
28 t[i] = t[loc] = 0; // 一定收回来
29 }
30 }
31 }
32
33 int main()
34 {
35 memset(t, 0, sizeof(t));
36 t[1] = 7;
37 t[2] = 4;
38 t[9] = t[1];
39 t[7] = t[2];
40
41 DFS(1);
42
43 return 0;
44 }
1 #include<iostream>
2 #include<string>
3 #include<cstring>
4
5 using namespace std;
6
7 typedef long long ll;
8 // MAX 有上限 85000
9 const ll MAX = 1009;
10
11 // 大数乘法
12 string BigMul(string x, string y)
13 { // 据说可以分治优化
14 string ret;
15 ll lenx = x.length();
16 ll leny = y.length();
17 // 被乘数、乘数、积
18 ll a[MAX], b[MAX], c[MAX];
19 memset(a, 0, sizeof(a));
20 memset(b, 0, sizeof(b));
21 memset(c, 0, sizeof(c));
22 for(ll i=lenx-1;i>=0;i--)
23 a[lenx-i] = x[i] - '0';
24 for(ll i=leny-1;i>=0;i--)
25 b[leny-i] = y[i] - '0';
26 // 第 i 位乘以 第 j 位为积的第 i+j-1 位(先不考虑进位)
27 for(ll i=1;i<=lenx;i++)
28 for(ll j=1;j<=leny;j++)
29 c[i+j-1] += a[i]*b[j];
30 // 处理进位
31 for(ll i=1;i<=lenx+leny;i++)
32 c[i+1] += c[i]/10, c[i] %= 10;
33 // 判断第 i+j 位是否为 0
34 if(c[lenx+leny]) ret += c[lenx+leny] + '0';
35 for(ll i=lenx+leny-1;i>=1;i--)
36 ret += c[i] + '0';
37
38 return ret;
39 }
40
41 // 大数比较大小
42 bool BigNumCmp(string a, string b)
43 {
44 if(a == b) return true;
45 ll la = a.length();
46 ll lb = b.length();
47 if(la > lb) return true;
48 if(la < lb) return false;
49 for(ll i=0;i<la;i++){
50 if(a.at(i) == b.at(i)) continue;
51 if(a.at(i) < b.at(i)) return false;
52 if(a.at(i) > b.at(i)) return true;
53 }
54 }
55
56 // 大数开方
57 string BigSqrt(string x)
58 {
59 string ret;
60 ll len = x.length();
61 ll ls = 0, i = 0;
62 if(len&1) ls = (len>>1) + 1;
63 else ls = len>>1;
64 for(ll i=0;i<ls;i++) ret += "0";
65 if(BigMul(ret, ret) == x) return ret;
66 while(ls--)
67 {
68 for(int k=0;k<10;k++){
69 if(BigMul(ret, ret) == x) return ret;
70 if(!BigNumCmp(BigMul(ret, ret), x)){
71 ret.at(i)++;
72 if(ret.at(i) == ':'){
73 ret.at(i)--;break;
74 }
75 }
76 else{
77 ret.at(i)--;break;
78 }
79 }
80 i++;
81 }
82
83 return ret;
84 }
85
86 int main()
87 {
88 string a, b;
89 char A[2*MAX];
90 // while(scanf("%s%s", &a[0], &b[0]))
91 gets(A);
92 {
93 int i=0;
94 for(;i<strlen(A);i++){
95 if(A[i] == ' '){
96 i++;break;
97 }
98 a.push_back(A[i]);
99 }
100 for(;i<strlen(A);i++) b.push_back(A[i]);
101 // cout<<BigMul(a, b)<<'\n';
102 // cout<<BigNumCmp(a, b)<<'\n';
103 // cout<<BigSqrt(a)<<'\n';
104 // cout<<BigMul(BigSqrt(a), BigSqrt(b))<<'\n';
105 // puts(BigMul(BigSqrt(a), BigSqrt(b)).c_str());
106 cout<<BigMul(BigSqrt(a), BigSqrt(b))<<'\n';
107 }
108
109 return 0;
110 }
1 // 分糖果
2 #include<iostream>
3 #include<cstring>
4 using namespace std;
5
6 int n = 0;
7
8 bool sure(int *a)
9 {
10 for(int i=0;i<n-1;i++)
11 for(int j=i+1;j<n;j++){
12 if(a[i] != a[j])
13 return false;
14 }
15 return true;
16 }
17
18 int fun(int *a)
19 {
20 int c = 0;
21 int b[101] = {0};
22 // int *b = new int(n);
23 memset(b, 0, sizeof(b));
24 while(1)
25 {
26 for(int i=0;i<n;i++){
27 b[i] = a[i] >>= 1;
28 }
29 for(int i=0;i<n-1;i++){
30 a[i] += b[i+1];
31 }
32 a[n-1] += b[0];
33 if(sure(a)) break;
34 for(int i=0;i<n;i++){
35 if(a[i]&1){
36 a[i]++;c++;
37 }
38 }
39 }
40 // delete []b;
41 return c;
42 }
43
44 int main()
45 {
46 while(cin>>n)
47 {
48 int a[101] = {0};
49 // int *a = new int(n);
50 memset(a, 0, sizeof(a));
51 for(int i=0;i<n;i++)
52 cin>>a[i];
53 cout<<fun(a)<<endl;
54
55 // delete []a;
56 }
57
58 return 0;
59 }
1 // 谁能告诉我为什么我少了一种......
2 #include<iostream>
3 #include<cstring>
4 #include<string>
5 #include<algorithm>
6
7 using namespace std;
8
9 const int MAX = 0xffff;
10
11 int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
12
13 int main()
14 {
15
16 int ans = 0;
17 while(next_permutation(a, a+9))
18 {
19 if(a[0] < a[2] && a[0] < a[3] && a[1] < a[3] && a[1] < a[4] && a[2] < a[5] && a[2] < a[6] && a[3] < a[7] && a[3] < a[6] && a[4] < a[7] && a[4] < a[8])
20 {
21 ans++;
22 cout<<0<<'\n';
23 cout<<a[0]<<' '<<a[1]<<'\n';
24 cout<<a[2]<<' '<<a[3]<<' '<<a[4]<<'\n';
25 cout<<a[5]<<' '<<a[6]<<' '<<a[7]<<' '<<a[8]<<'\n';
26 }
27 }
28
29 cout<<767<<'\n';
30
31 return 0;
32 }