徐涛 4 years ago
parent a3f0438c78
commit 49c9b9c679

@ -1,5 +1,21 @@
{
"files.associations": {
"iostream": "cpp"
"iostream": "cpp",
"ostream": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"set": "cpp",
"random": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"istream": "cpp",
"limits": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"streambuf": "cpp",
"regex": "cpp",
"tuple": "cpp",
"valarray": "cpp"
}
}

@ -3,9 +3,36 @@ git status
git add .
git commit -m ""
git push -u origin master
---
# `# include <bits/stdc++.h>`
## 高精度
1. python打表
2. 高精加和高精乘
```cpp
void pplus(int *a, int *c)
{
int jw = 0;
for (int i = 0; i < 1000; i++)
{
c[i] += a[i] + jw;
jw = c[i] / 10;
c[i] %= 10;
}
}
void pmultiply(int *a, int c)
{
int jw = 0;
for (int i = 0; i < 1000; i++)
{
a[i] = a[i] * c + jw;
jw = a[i] / 10;
a[i] %= 10;
}
}
```
## 筛法
1. 打表
@ -59,4 +86,104 @@ void prime(int b)
}
}
}
```
```
## 矩阵旋转
1. 找规律
---
## 重定向
```cpp
freopen(file,"r",stdin);
freopen(file,"w",stdout);
```
## 随机数的产生
1. 初始化随机数种子 `srand(time(NULL))`
2. rand()
## STL初步
1. sort(开始,结束,比较函数)
```cpp
struct Node
{
int a, b;
};
Node a[100];
bool cmp(Node a, Node b)
{
if (a.a != b.a)
return a.a > b.a;
return a.b > b.b;
}
sort(a, a + 100, cmp);
```
2. 不定长数组 vector
```cpp
#include <bits/stdc++.h>
vector<int> a;
a.size()
a.resize()
a.push_back()
a.pop_back()
a.clear()
```
3. 集合 set
```cpp
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
set<int> a, b;
typedef set<int>::iterator SI;
a.insert(1);
a.count(1);
for (SI i = a.begin(); i != a.end(); i++)
; //遍历
set_union(ALL(a), ALL(b), INS(a)); //并集放入a中
set_intersection(ALL(a), ALL(b), INS(a)); //交集放入a中
```
4. 映射 map 类似python中的字典
```cpp
map<string,int> dict;
dict['r']=1;//这里dict使用的是string的方法而dict[]使用的是int的方法
```
5. 栈(后进先出),队列(先进先出)
```cpp
stack<int> s;
s.top();
s.push(1);
s.pop();
s.empty();
queue<int> x;
x.front();
x.pop();
x.push(1);
x.empty();
```
6. 优先级队列
```cpp
struct cmp
{
bool operator()(const int a, const int b)
{
return a > b;
//当a>b时返回ture也就是说越大优先级越小
//出队列时先弹出小的小的在队列top
}
};
priority_queue<int, vector<int>, cmp> a;
a.push(1);
a.pop();
a.top();
a.size();
a.empty();
```
### 注意点
1. vector作为参数或返回值时尽量使用传引用会改变传入的参数。或者直接全局变量传都不要传。
2. 结构体静态变量: static 变量名
---

@ -0,0 +1,134 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
char start[10][11], end[10][11];
for (int i = 0; i < n; i++)
cin >> start[i];
for (int i = 0; i < n; i++)
cin >> end[i];
int flag = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (start[i][j] != end[j][n - 1 - i])
{
flag = 0;
break;
}
}
if (flag == 1)
{
cout << 1;
return 0;
}
flag = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (start[i][j] != end[n - 1 - i][n - 1 - j])
{
// cout<<i<<" "<<j<<" ";
// cout << start[i][j] << "!=" << end[n - 1 - j][n - 1 - i] << endl;
flag = 0;
break;
}
}
if (flag == 1)
{
cout << 2;
return 0;
}
flag = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (start[i][j] != end[n - 1 - j][i])
{
flag = 0;
break;
}
}
if (flag == 1)
{
cout << 3;
return 0;
}
flag = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (start[i][j] != end[n - 1 - i][j])
{
flag = 0;
break;
}
}
if (flag == 1)
{
cout << 4;
return 0;
}
char temp[10][11];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
temp[n - 1 - i][j] = start[i][j];
}
/////////////////
int f1 = 1, f2 = 1, f3 = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (temp[i][j] != end[j][n - 1 - i])
{
f1 = 0;
break;
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (temp[i][j] != end[n - 1 - j][n - 1 - i])
{
f2 = 0;
break;
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (temp[i][j] != end[n - 1 - j][i])
{
f3 = 0;
break;
}
}
if (f1 || f2 || f3)
{
cout << 5;
return 0;
}
flag = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (start[i][j] != end[i][j])
{
flag = 0;
break;
}
}
if (flag == 1)
{
cout << 6;
return 0;
}
cout << 7;
////////////////
return 0;
}

Binary file not shown.

@ -0,0 +1,9 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
return 0;
}

Binary file not shown.

@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
//都很慢
string line;
while (getline(cin, line))
{
int sum = 0, x;
stringstream ss(line);
while (ss >> x)
{
sum += x;
}
cout << sum << endl;
}
return 0;
}

Binary file not shown.

@ -3,23 +3,49 @@ using namespace std;
void pplus(int *a, int *c)
{
int jw = 0;
for (int i = 1; i <= 1000; i++)
for (int i = 0; i <= 999; i++)
{
c[i] += a[i] + jw;
jw = c[i] / 10;
c[i] %= 10;
}
}
void pmultiply(int *a, int c)
void pmultiply(int *a, int c, int *b)
{
int jw = 0;
for (int i = 0; i < 1000; i++)
for (int i = 0; i <= 999; i++)
{
a[i] = a[i] * c + jw;
jw = a[i] / 10;
a[i] %= 10;
b[i] = a[i] * c + jw;
jw = b[i] / 10;
b[i] %= 10;
// cout << a[i];
}
}
void display(int *a)
{
int flag = 0;
for (int i = 999; i >= 0; i--)
{
while (flag == 0 && i >= 0 && a[i] == 0)
{
i--;
}
flag = 1;
if (i < 0)
{
cout << 0;
break;
}
cout << a[i];
}
cout << endl;
}
// void f(int sum[][1000], int n)
// {
// for (int i = 1; i <= n; i++)
// display(sum[i]);
// cout << endl;
// }
//用高精度计算出 S = 1! + 2! + 3! + \cdots + n!S=1!+2!+3!+⋯+n!n \le 50n≤50
int main()
{
@ -35,19 +61,24 @@ int main()
int sum[51][1000];
memset(sum, 0, sizeof(int) * 1000);
sum[0][0] = 1;
// for (int i = 0; i < n + 1; i++)
// {
// display(sum[i]);
// }
// cout << endl;
for (int i = 1; i < n + 1; i++)
{
pmultiply(sum[i], i);
pmultiply(sum[i - 1], i, sum[i]);
}
// f(sum, n);
// cout << "start";
for (int i = 2; i < n + 1; i++)
{
// f(sum, n);
pplus(sum[i - 1], sum[i]);
// f(sum, n);
}
for (int i = 999; i >= 0; i--)
{
while (sum[n][i] == 0)
i--;
cout << sum[n][i];
}
display(sum[n]);
return 0;
}

Binary file not shown.
Loading…
Cancel
Save