main
黄海 2 years ago
commit 59632ede27

5
.gitignore vendored

@ -0,0 +1,5 @@
*/cmake-build-debug/
*.sql.gz
/TangDou/cmake-build-debug-mingw
/TangDou/cmake-build-debug
/TangDou/*.exe

@ -0,0 +1,85 @@
{
"files.associations": {
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"coroutine": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cuchar": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"scoped_allocator": "cpp",
"shared_mutex": "cpp",
"span": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
}
}

28
.vscode/tasks.json vendored

@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "C:\\TDM-GCC-64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}

@ -0,0 +1,23 @@
共136题
[AcWing 语法基础课 笔记](https://blog.csdn.net/PxxxxN/article/details/113032355)
1. A + B
https://www.acwing.com/problem/content/1/
608. 差
https://www.acwing.com/problem/content/610/
604. 圆的面积
https://www.acwing.com/problem/content/606/
606. 平均数1
https://www.acwing.com/problem/content/608/
609. 工资
https://www.acwing.com/problem/content/611/
615. 油耗
https://www.acwing.com/problem/content/617/
TODO

@ -0,0 +1 @@
https://www.cnblogs.com/fusiwei/p/11559403.html

@ -0,0 +1,25 @@
#include <bits/stdc++.h>
using namespace std;
vector<int> v(0);
int x;
int main() {
vector<int>::iterator iter;
v.insert(v.begin(), 1);
v.insert(v.begin(), 2);
v.insert(v.begin(), 3);
v.insert(v.begin(), 4);
v.push_back(5);
for (iter = v.begin(); iter != v.end(); ++iter)
cout << *iter << " ";
cout << v.empty() << endl;
cout << v.size()<< endl;
v.clear();
v.erase(v.begin());
return 0;
}

@ -0,0 +1,2 @@
【鱼同学的算法讲堂】一听就会的超基础数据结构
https://www.bilibili.com/video/av39988212

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 KiB

@ -0,0 +1,25 @@
#include<bits/stdc++.h>**//万能头文件
using namespace std;//流操作命名空间
//递归
string dfs(int n){
//返回处理后的字符一直递归直至全部处理完0,1,2必须特判跳出
string out="";//存储输出
int k=-1,i=1;bool ff[16];//临时变量;
//
for(int i=0;i<=15;i++){
ff[i]=n&1;n=n>>1;//二进制取位运算取得所有的为1的二进位表示可以操作
}
for(int i=15;i>=0;i--){
if(ff[i]){//判断是否为1
if(i>=2)out+="2(" + dfs(i) + ")+";//二以上则再次递归指数
if(i==1)out+="2+";//特判1
if(i==0)out+="2(0)+";//特判0
}
}
return out.substr(0,out.size()-1);//返回//去除尾部‘+
}
int main(){
int n;cin>>n;
cout<<dfs(n);
return 0;
}

@ -0,0 +1,40 @@
#include<iostream>
#include <stdlib.h>
using namespace std;
int main() {
char a[13];
int sum=0;
for(int i=0; i<13; i++) {
cin >>a[i];
}
int k=0;
for(int i=0; i<11; i++) {
if(a[i]!='-') {
k++;
int b=a[i]-48;
sum+=b*k;
}
}
int c=sum%11;
char c2;
if(c==10) {
c2='X';
} else {
c2=c+48;
}
if(c2==a[12]) {
cout<<"Right"<<endl;
return 0;
} else {
a[12]=c2;
for(int i=0; i<13; i++) {
cout<<a[i];
}
}
return 0;
}

@ -0,0 +1,66 @@
#include<bits/stdc++.h>
using namespace std;
char c[100001];
int a,b,i,j,k,n;
int main()
{
for(n=1;;++n)
{
cin>>c[n];
if(c[n]=='E')
break;
}
a=0;
b=0;
for(i=1;i<n;++i)
if(c[i]=='W')
{
++a;
if(a>=11)
if((a-b)>=2)
{
cout<<a<<':'<<b<<endl;
a=0;
b=0;
}
}
else
{
++b;
if(b>=11)
if((b-a)>=2)
{
cout<<a<<':'<<b<<endl;
a=0;
b=0;
}
}
cout<<a<<':'<<b<<"\n\n";
a=0;
b=0;
for(i=1;i<n;++i)
if(c[i]=='W')
{
++a;
if(a>=21)
if((a-b)>=2)
{
cout<<a<<':'<<b<<endl;
a=0;
b=0;
}
}
else
{
++b;
if(b>=21)
if((b-a)>=2)
{
cout<<a<<':'<<b<<endl;
a=0;
b=0;
}
}
cout<<a<<':'<<b;
return 0;
}

@ -0,0 +1 @@
https://www.luogu.org/problemnew/solution/P1042?page=2

@ -0,0 +1,19 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,a,i;
cin>>n;
for(i=n; i>=0; i--) {
//倒着输入便于下面输出x的几次方
cin>>a;
if(a) { //判定a是否为真即不等于0
if(i!=n&&a>0) cout<<"+"; //i=n第一项不用符号
if(abs(a)>1||i==0) cout<<a;//abs是绝对值函数最后一项或不是-1或1时输出。
if(a==-1&&i) cout<<"-"; //-1省略1
if(i>1) cout<<"x^"<<i;
if(i==1) cout<<"x"; //指数为1时省略1
}
}
return 0;
}

@ -0,0 +1,24 @@
#include<bits/stdc++.h>
using namespace std;
int p1,p2,p3,i=0,k;
char ch[300],be,af,f,j,p;//p用于输出;
int main() {
scanf("%d%d%d%s",&p1,&p2,&p3,ch);//输入;
while(ch[i]){//当ch[i]有值时;
be=ch[i-1];af=ch[i+1];f=ch[i];//f存储ch[i],便于判断;
if(f=='-'&&af>be&&(be>='0'&&af<='9'||be>='a'&&af<='z')){//意思是ch[i]若为'-',就判断其前后是否满足条件,满足进入循环;
for(p3==1?j=be+1:j=af-1; p3==1?j<af:j>be; p3==1?j++:j--){
p=j;//j是整形变量p是字符型变量这样是将p赋值为ASCII码为j的字符;
if(p1==2)//是否大写;
p=(p>='a')?p-32:p;//如果是字母就转成大写
else if(p1==3) p='*';//是否输出'*'
for(k=0; k<p2; k++)//输出p2个
printf("%c",p);
}
}
else
printf("%c",f);//如果ch[i]是非'-'或者其前后不满足条件,就原样输出;
i++;//一定要放在后面不然会出错QAQ;
}
return 0;
}

@ -0,0 +1,50 @@
#include<bits/stdc++.h>
using namespace std;
map<char,char>m0,m1; //m0记录密文对明文m1记录明文对密文
char miwen[10000],mingwen[10000],target[10000];
int main()
{
gets(miwen);//输入密文
gets(mingwen);//输入明文
gets(target);//输入要翻译的信息
//第一个for循环用来记录明文和密文的对应关系
for(int i=0;i<strlen(miwen);i++)
{
//判断密文多对一或明文多对一的情况如果符合这种情况说明和规则不符直接输出Failed
if((m0.count(miwen[i]) && m0[miwen[i]]!=mingwen[i]) || (m1.count(mingwen[i]) && m1[mingwen[i]]!=miwen[i]))
{
cout<<"Failed";
return 0;
}
//如果符合规则,则记录
else
{
m0[miwen[i]]=mingwen[i];
m1[mingwen[i]]=miwen[i];
}
}
//第二个for循环用来判断是否符合第一条规则即A~Z全部有对应的密文
char temp='A';
for(int i=0;i<26;i++)
{
//判断是否A~Z都有密文如果发现没有密文的说明和规则不符直接输出Failed
if(!m1.count(temp+i))
{
cout<<"Failed";
return 0;
}
}
//如果运行到了这里说明所有规则都符合。直接第三个for循环输出结果
for(int i=0;i<strlen(target);i++)
{
if(target[i]!=' ')//注意输入的翻译信息行末有空格!!
cout<<m0[target[i]];
}
return 0;
}

@ -0,0 +1,39 @@
#include<iostream>
#include<map>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
map<char,int>m;
int main(){
int maxx=-999999,minn=999999;
char a[101];
cin>>a;
int l=strlen(a);
for(int i=0;i<l;i++){
m[a[i]]++;
maxx=max(maxx,m[a[i]]);
//minn=min(minn,m[a[i]]);
}
for(int i=0;i<l;i++){
minn=min(minn,m[a[i]]);
}
//cout<<maxx<<' '<<minn<<endl;
maxx-=minn;
// cout<<maxx<<endl;
if(maxx==0||maxx==1){
cout<<"No Answer"<<endl;
cout<<0;
return 0;
}
for(int i=2;i<=sqrt(maxx);i++){
if(maxx%i==0){
cout<<"No Answer"<<endl;
cout<<0;
return 0;
}
}
cout<<"Lucky Word"<<endl;
cout<<maxx;
return 0;
}

@ -0,0 +1 @@
https://www.luogu.org/problemnew/solution/P1125

@ -0,0 +1 @@
https://blog.csdn.net/weixin_44312186/article/details/88785561

@ -0,0 +1,27 @@
#include<bits/stdc++.h>
#define maxn 1000
using namespace std;
int dp[maxn];
int main() {
int n;
scanf("%d", &n);
int a[maxn];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
dp[0] = a[0];//边界 (结果总是确定的,动态规划总是从这些边界出发)
for (int i = 0; i < n; i++) {
dp[i] = max(a[i], dp[i - 1] + a[i]);//递推式
}
//dp[i]存放以a[i]结尾的连续序列的最大和需要遍历i得到最大的才是结果
int k = 0;
for (int i = 0; i < n; i++) {
if (dp[i] > dp[k]) {
k = i;
}
}
printf("%d\n", dp[k]);
return 0;
}

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, n;//x表示要分离线所在的行或列 n指这条线能分开说话人的数量
} y[1001], x[1001];//x是行 y为列
bool cmp1(point a, point b) {
return a.n > b.n;//排序时将分离数量大的放前面保证最优
}
bool cmp2(point a, point b) {
return a.x < b.x;//出答案时要求列数(行数)小的在前
}
int main() {
int m, n, k, l, d;//同题
scanf("%d %d %d %d %d", &m, &n, &k, &l, &d);
int x1, y1, p1, q1;//同题
for (int i = 1; i <= d; i++) {//
scanf("%d %d %d %d", &x1, &y1, &p1, &q1);
if (x1 == p1) {//辨别是纵向还是横向,若横向相同则分离线为纵向
y[min(y1, q1)].x = min(y1, q1);//标记分离线所在列数
y[min(y1, q1)].n++;//y[min(y1,q1)].x保证相同列数分离线叠加
}
if (y1 == q1) {//同理
x[min(x1, p1)].x = min(x1, p1);
x[min(x1, p1)].n++;
}
}
sort(x + 1, x + 1 + 1000, cmp1);//分离数大的在前
sort(y + 1, y + 1 + 1000, cmp1);
sort(x + 1, x + 1 + k, cmp2);//将答案进行整理(行数或列数小在前)
sort(y + 1, y + 1 + l, cmp2);
for (int i = 1; i <= k; i++)
printf("%d ", x[i].x);
printf("\n");//输出中间换行
for (int i = 1; i <= l; i++)
printf("%d ", y[i].x);
return 0;
}

@ -0,0 +1 @@
https://www.luogu.org/problemnew/solution/P1056?page=4

@ -0,0 +1,42 @@
#include<bits/stdc++.h>
using namespace std;
int Fun(int n)
{
//用数组列出0-9没一个数所需要的火柴棍数
int arr[10] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int ret = 0;
//判断n是不是两位数或更高位数
while (n / 10 != 0){
//将个位数所需要的火柴棍数相加
ret += arr[n % 10];
//更新n的个位数
n /= 10;
}
//最后加上此时n需要的火柴棍数(n是一位数)
ret += arr[n];
return ret;
}
int main()
{
int a, b, c, m, num = 0;
//printf("请输入火柴棍的个数\n");
scanf("%d", &m);
//枚举a和b
for (a = 0; a <= 1111; a++){
for (b = 0; b <= 1111; b++){
c = a + b;
//判读是否符合条件
if (Fun(a) + Fun(b) + Fun(c) == m - 4){
//printf("%d + %d = %d\n", a, b, c);
//计算所有可能的个数
num++;
}
}
}
//printf("一共可以拼出%d个不同等式\n", num);
//system("pause");
cout<<num;
return 0;
}

@ -0,0 +1,17 @@
#include<iostream>
using namespace std;
int a[15];
int main() {
int b,B,A;
for(int i=1; i<=10; i++)
cin>>a[i];
cin>>b;
B=b+30;
int c=0;
for(int i=1; i<=10; i++) {
if(a[i]<=B)
c++ ;
}
cout<<c;
return 0;
}

@ -0,0 +1,5 @@
树状数组 数据结构详解与模板(可能是最详细的了)
https://blog.csdn.net/bestsort/article/details/80796531
树状数组入门(简单的原理讲解)
https://www.cnblogs.com/findview/archive/2019/08/01/11281628.html

@ -0,0 +1,39 @@
#include <iostream>
using namespace std;
int main()
{
char ch[26],l,r;
int w,i,k,j;
cin>>i>>j>>w;
l=i+'a'-1; //把数字转换成字母
r=j+'a'-1;
cin>>ch;
for(i=1;i<=5;i++)
{
j=w-1; //从'个位'开始加
cout<<"从'个位'开始加 i的数值"<<i<<endl;
//------------------------------------------------重
while(j>=0&&ch[j]==r+j+1-w)
{
printf("%c ",r+j+1-w);
cout<<ch[j]<<" "<<"ttt这个时候的j"<<j<<" 这个时候的ch"<<ch<<endl;
j--; //找到当前为了把数变大,所必须进的位最小在哪
}
if(j==-1)
break;
//------------------------------------------------点
cout<<"yuanlai"<<ch[j];
ch[j]++; //进位
cout<<"升级进位变成:"<<ch[j]<<endl;
for (k=j+1;k<=w-1;k++)
ch[k]=ch[k-1]+1; //所需进位之后的所有位都需变大
cout<<ch<<endl;
}
return 0;
}
/*
1<2<3<4...
Jama>b>c>d...
*/

@ -0,0 +1,6 @@
P1061 Jam的计数法
https://www.luogu.org/problem/P1061
ACMNO.51 JAM计数法(字母顺序之间的排列问题)
https://blog.csdn.net/weixin_42859280/article/details/89387129

@ -0,0 +1,15 @@
#include<iostream>
using namespace std;
int main () {
int a,b,s,max=0,i,day=0;
for (i=1; i<8; i++) {
cin>>a>>b;
s=a+b;
if ((s>max)&&(s>8)) {
max=s;
day=i;
}
}
cout<<day;
return 0;
}

@ -0,0 +1,26 @@
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
int i,month,left=0,save=0,sum,plan,flag=0;
for(month=1; month<=12; month++) {
left+=300;
scanf("%d",&plan);
left = left - plan;
if(left<0) {
flag=1;
break;
} else {
i = left/100;
save += (100*i);
left -= (100*i);
}
}
if(flag>0)
printf("-%d",month);
else {
sum=((1.2*save) + left);
printf("%d",sum);
}
return 0;
}

@ -0,0 +1,46 @@
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
struct hs //指花生:)
{
int x, y, v;
bool operator < (const hs & a) const
{
return v < a.v;
}//优先队列默认从大到小排序,但是需要用到小于号,所以这里重载运算符 < (只重载<就可以了)
};
priority_queue <hs> q;
int main()
{
int m, n, k;
int sum = 0;
cin >> m >> n >> k;
int a;
hs t;
for(int i = 1; i <= m; i++)
for(int j = 1; j <= n; j++)
{
cin >> a;
t.v = a;
t.x = j;
t.y = i;
if(a != 0) //如果有数值,就推进队列
q.push(t);
}
k -= q.top().y; //走到最大的花生植株
while(!q.empty() && k > q.top().y) //第一个是检验队列不为空,如果空了说明全摘完了,第二个是检验剩余的时间可以走回路边
{
k--; //只要进入一次循环说明到了一棵植株采摘耗费1时间
sum += q.top().v;
int lx = q.top().x, ly = q.top().y;
q.pop();//换下一棵树
k -= abs(lx - q.top().x) + abs(ly - q.top().y);//剩余的时间减去从上一棵植株到这棵的时间
}
cout << sum << endl;
return 0;
}

@ -0,0 +1,3 @@
https://www.luogu.org/problem/P1086
https://www.luogu.org/problemnew/solution/P1086?page=7

@ -0,0 +1,29 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,score1,score2,sum=0,max=0,total=0,x,i;
char a,b;
string name,maxn;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>name>>score1>>score2>>a>>b>>x;
if(score1>80 && x>0)//判断是否获得院士奖学金
sum+=8000;
if(score1>85 && score2>80)//判断是否获得五四奖学金
sum+=4000;
if(score1>90)//判断是否获得成绩优秀奖
sum+=2000;
if(score1>85 && b=='Y')//判断是否获得西部奖学金
sum+=1000;
if(score2>80 && a=='Y')//判断是否获得班级贡献奖
sum+=850;
total+=sum;//累加奖学金
if(sum>max)//找出最牛学生
maxn=name,max=sum;//sum的用处
sum=0;
}
cout<<maxn<<endl<<max<<endl<<total;
return 0;
}

@ -0,0 +1,7 @@
https://www.cnblogs.com/five20/p/7534747.html
信息学竞赛刷题建议历程
https://blog.csdn.net/cnyali/article/details/41688175
省一,洛谷题要刷到哪种阶段?
https://www.zhihu.com/question/296752963?sort=created

@ -0,0 +1,16 @@
【鱼同学的算法讲堂】数据结构专题之线段树基础
https://www.bilibili.com/video/av37703183/?redirectFrom=h5
线段树入门
https://www.bilibili.com/video/av40667689/?spm_id_from=333.788.videocard.4
菜鸟都能理解的线段树入门经典
https://blog.csdn.net/ray_seu/article/details/8705640
线段树--从入门到入土
https://www.cnblogs.com/rmy020718/p/9571490.html
线段树(超基础版)
https://www.bilibili.com/video/av47446422/

@ -0,0 +1,9 @@
树状数组
https://blog.csdn.net/bestsort/article/details/80796531#main-toc
区间修改 单点查询
差分
为什么不用线段树?因为常数大,可能跑不过?

@ -0,0 +1,86 @@
#include <iostream>
using namespace std;
struct Line {
int left, right, count;
Line *leftChild, *rightChild;
Line(int l, int r): left(l), right(r) {}
};
//建立一棵空线段树
void createTree(Line *root) {
int left = root->left;
int right = root->right;
if (left < right) {
int mid = (left + right) / 2;
Line *lc = new Line(left, mid);
Line *rc = new Line(mid + 1, right);
root->leftChild = lc;
root->rightChild = rc;
createTree(lc);
createTree(rc);
}
}
//将线段[l, r]分割
void insertLine(Line *root, int l, int r) {
cout << l << " " << r << endl;
cout << root->left << " " << root->right << endl << endl;
if (l == root->left && r == root->right) {
root->count += 1;
} else if (l <= r) {
int rmid = (root->left + root->right) / 2;
if (r <= rmid) {
insertLine(root->leftChild, l, r);
} else if (l >= rmid + 1) {
insertLine(root->rightChild, l, r);
} else {
int mid = (l + r) / 2;
insertLine(root->leftChild, l, mid);
insertLine(root->rightChild, mid + 1, r);
}
}
}
//树的中序遍历(测试用)
void inOrder(Line* root) {
if (root != NULL) {
inOrder(root->leftChild);
printf("[%d, %d], %d\n", root->left, root->right, root->count);
inOrder(root->rightChild);
}
}
//获取值n在线段上出现的次数
int getCount(Line* root, int n) {
int c = 0;
if (root->left <= n&&n <= root->right)
c += root->count;
if (root->left == root->right)
return c;
int mid = (root->left + root->right) / 2;
if (n <= mid)
c += getCount(root->leftChild, n);
else
c += getCount(root->rightChild, n);
return c;
}
int main() {
int l[3] = {2, 4, 0};
int r[3] = {5, 6, 7};
int MIN = l[0];
int MAX = r[0];
for (int i = 1; i < 3; ++i) {
if (MIN > l[i]) MIN = l[i];
if (MAX < r[i]) MAX = r[i];
}
Line *root = new Line(MIN, MAX);
createTree(root);
for (int i = 0; i < 3; ++i) {
insertLine(root, l[i], r[i]);
}
inOrder(root);
int N;
while (cin >> N) {
cout << getCount(root, N) << endl;
}
return 0;
}

@ -0,0 +1,16 @@
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
priority_queue<int,vector<int>,greater<int> >q;
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>x,q.push(x);
while(q.size()>=2){
int a=q.top(); q.pop();
int b=q.top(); q.pop();
ans+=a+b;
q.push(a+b);
}
cout<<ans<<endl;
return 0;
}

@ -0,0 +1,63 @@
#include<bits/stdc++.h>
using namespace std;
double maxx,mo=0,d2,temlen=0,d1,c,p;
//temlen油箱中在到达了下一个加油站时油箱中的剩余油量可以继续走的路程
int n;
struct add
{
double co;
double dis;
}pl[10000];//加油站结构体dis-距离起点的距离co油价
int move(int now)//1.now:现在到达的加油站
{
int can=99999;
int f=pl[now].dis;
for(int i=now+1;i<=n&&pl[i].dis-f<=maxx;i++)
{
if(pl[i].co<pl[now].co)//2.
{
mo+=((pl[i].dis-f-temlen)/d2)*pl[now].co;
temlen=0;
return i;
}
if(can==99999||pl[i].co<pl[can].co)can=i;
}
if(d1-pl[now].dis<=maxx)
{
mo+=((d1-pl[now].dis-temlen)/d2)*pl[now].co;
return 9999;
}
if(can==99999)//4.
{
cout<<"No Solution";
return -1;
}
else//3.
{
mo+=c*pl[now].co;
temlen+=(maxx-pl[can].dis+f);
return can;
}
}
int cmp(add a,add b)
{
return a.dis<b.dis;
}
int main()
{
cin>>d1>>c>>d2>>p>>n;
pl[0].dis=0;
pl[0].co=p;
for(int i=1;i<=n;i++)cin>>pl[i].dis>>pl[i].co;
sort(pl,pl+n,cmp);
maxx=c*d2;
int k=0,t;
do
{
t=move(k);
k=t;
if(t==-1)return 0;
}while(t!=9999);
printf("%.2f",mo);
return 0;
}

@ -0,0 +1 @@
https://blog.csdn.net/largecub233/article/details/68923039

@ -0,0 +1,26 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
int a[N] = {0};
for(int i=0;i<N;i++)
{
cin>>a[i];
}
sort(a, a + N, less<int>() );
int n = unique(a, a + N) - a;
cout<<n<<endl;
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
return 0;
}

@ -0,0 +1,76 @@
#include<bits/stdc++.h>
using namespace std;
/*
C++ STL
pushpop
5 3 2 4 6push
6 5 4 3 2
https://www.cnblogs.com/aiguona/p/7200718.html
* */
struct node {
friend bool operator<(node n1, node n2) {
return n1.priority < n2.priority;
}
int priority;
int value;
};
int main() {
const int len = 5;
int i;
int a[len] = {3, 5, 9, 6, 2};
//示例1从大到小输出
//priority_queue<int, vector<int>, less<int> > qi; //大顶堆
priority_queue<int> qi; //简写版本
for (i = 0; i < len; i++)
qi.push(a[i]);
for (i = 0; i < len; i++) {
cout << qi.top() << " ";
qi.pop();
}
cout << endl;
//示例2从小到大输出
priority_queue<int, vector<int>, greater<int> > qi2; //小顶堆
for (i = 0; i < len; i++)
qi2.push(a[i]);
for (i = 0; i < len; i++) {
cout << qi2.top() << " ";
qi2.pop();
}
cout << endl;
//示例3按优先级输出
priority_queue<node> qn;
node b[len];
b[0].priority = 6;
b[0].value = 1;
b[1].priority = 9;
b[1].value = 5;
b[2].priority = 2;
b[2].value = 3;
b[3].priority = 8;
b[3].value = 2;
b[4].priority = 1;
b[4].value = 4;
for (i = 0; i < len; i++)
qn.push(b[i]);
cout << "优先级" << '\t' << "" << endl;
for (i = 0; i < len; i++) {
cout << qn.top().priority << '\t' << qn.top().value << endl;
qn.pop();
}
return 0;
}

@ -0,0 +1,31 @@
#include<bits/stdc++.h>
using namespace std;
/*
STL
nmmnnm
m=nnn!
https://www.cnblogs.com/aiguona/p/7304945.html
*/
using namespace std;
int main() {
int arr[] = {3, 2, 1};
cout << "用prev_permutation对3 2 1的全排列" << endl;
do {
cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << '\n';
} while (prev_permutation(arr, arr + 3)); ///获取上一个较大字典序排列如果3改为2只对前两个数全排列
int arr1[] = {1, 2, 3};
cout << "用next_permutation对1 2 3的全排列" << endl;
do {
cout << arr1[0] << ' ' << arr1[1] << ' ' << arr1[2] << '\n';
} while (next_permutation(arr1, arr1 + 3)); ///获取下一个较大字典序排列如果3改为2只对前两个数全排列
///注意数组顺序,必要时要对数组先进行排序
return 0;
}

@ -0,0 +1,48 @@
#include<bits/stdc++.h>
using namespace std;
/*
C++ STL
线线
(Queue)线()
()(rear) (Front),
https://www.cnblogs.com/aiguona/p/7200837.html
* */
int main()
{
//队列
queue<int> q;
//栈
stack<char> s;
//放入第一个元素1
q.push(1);
//判断是不是为空
cout << q.empty() << endl; //如果栈为空返回true否则返回false
//放入第二个元素2
q.push(2);
cout << q.front() << endl;
q.pop();
// 返回队首元素的值,但不删除该元素
cout << q.front() << endl;
//删除队列首元素但不返回其值
q.pop();
//如果栈为空返回true否则返回false
cout << q.empty() <<endl;
//======================================================================
//存入元素2
s.push(2);
cout << s.top() <<endl;
//返回栈顶的元素,但不删除该元素
s.push(3);
cout << s.top();
s.pop();
cout << s.top();
}

@ -0,0 +1,47 @@
#include<bits/stdc++.h>
using namespace std;
/*
C++ STL vector
vector():
vector
访
https://www.cnblogs.com/aiguona/p/7228364.html
* */
int main() {
vector<int> v; //定义vector
vector<int>::iterator it; //定义一个vector迭代器
for (int i = 10; i >= 1; i--) //插入数据
v.push_back(i);
cout << "输出:";
for (it = v.begin(); it != v.end(); it++) //输出迭代器的值
cout << *it << " ";
cout << endl;
it -= 1;
cout << "最后一个的值为:" << *it << " " << endl;
v.erase(it); //删除最后一个元素
cout << "元素个数:" << v.size() << endl; //输出元素个数
sort(v.begin(), v.end()); //vector排序
cout << "排序后:";
for (it = v.begin(); it != v.end(); it++) //输出vector元素
cout << *it << " ";
cout << endl;
v.insert(v.begin(), 100); //在pos位置插入一个elem
cout << "第一个元素为:" << v.front() << endl;//输出第一个元素
v.pop_back(); //去掉最后一个元素
cout << "元素个数:" << v.size() << endl;//输出元素个数
v.clear(); //vector清空
cout << "清空后元素个数:" << v.size() << endl; //输出元素个数
return 0;
}

@ -0,0 +1,42 @@
#include<bits/stdc++.h>
using namespace std;
/*
C++ STL pair
pairstruct
便使 c++pair pair, struct
pair pair struct .
pair pair <int ,pair<int ,int > > > > >>
https://www.cnblogs.com/aiguona/p/7231377.html
* */
typedef pair<string, string> au; //利用typedef简化其声明
int main() {
int flag;
string x1, x2;
pair<string, string> p1("a", "bc"); //创建一个pair对象它的两个元素分别为string和string类型其中first成员初始化为“a”而second成员初始化为“ab”
pair<string, string> p2("a", "aa");
au p3;
string name;
name = p1.second; //返回1中名为second的数据成员
cout << p1.first << endl;
cout << name << endl;
flag = p1 < p2;
cout << flag << endl; //判断两个pair对象的大小按字典次序
flag = p1 > p2;
cout << flag << endl;
//用例 8 James
while (cin >> x1 >> x2) {
p3 = make_pair(x1, x2); //生成一个新的pair对象
cout << p3.first << "****" << p3.second << endl;
}
return 0;
}

@ -0,0 +1,40 @@
#include<bits/stdc++.h>
using namespace std;
/*
STL set
setset set
set
https://www.cnblogs.com/aiguona/p/7231399.html
* */
int main() {
int i;
set<int> set1;
for (i = 0; i < 10; ++i)
set1.insert(i);
//迭代器
set<int>::iterator it;
for (it = set1.begin(); it != set1.end(); it++)
cout << *it << "\t";
cout << endl;
//把3插入到set1中,插入成功则set1.insert(3).second返回1否则返回0.
set1.erase(5);
if (set1.insert(3).second)
cout << "set insert success";
else
cout << "set insert failed";
cout << endl;
//迭代输出
set<int>::iterator itr;
for (itr = set1.begin(); itr != set1.end(); itr++)
cout << *itr << "\t";
set1.clear();
return 0;
}

@ -0,0 +1,29 @@
#include<bits/stdc++.h>
using namespace std;
/*
STL map
MapSTLmap
https://www.cnblogs.com/aiguona/p/7231451.html
* */
int main() {
map<char, int> a;//定义map函数
a.insert(map<char, int>::value_type('c', 1));//插入元素
a.insert(map<char, int>::value_type('d', 2));
map<char, int>::iterator b = a.find('c');//查找元素
map<char, int>::const_iterator it;
for (it = a.begin(); it != a.end(); ++it)
cout << it->first << "=" << it->second << endl;
cout << endl;
a.clear();//删除所有元素
return 0;
}

@ -0,0 +1,34 @@
#include<bits/stdc++.h>
using namespace std;
/*
STL list
listlist
list线list便listinsertsplice list listerase
https://www.cnblogs.com/aiguona/p/7231609.html
*/
using namespace std;
int main() {
list<string> test;
test.push_back("back"); //back
test.push_front("middle"); //middle back
test.push_front("front"); //front middle back
cout << test.front() << endl; //front
cout << *test.begin() << endl; //front
cout << test.back() << endl; //back
cout << *(test.rbegin()) << endl; //back
test.pop_front(); //middle back
test.pop_back(); //middle
cout << test.front() << endl; //middle
}

@ -0,0 +1,61 @@
#include<bits/stdc++.h>
using namespace std;
/*
STL deque
Deque
https://www.cnblogs.com/aiguona/p/7281739.html
*/
using namespace std;
int main() {
deque<int> ideq(20); //Create a deque ideq with 20 elements of default value 0
deque<int>::iterator pos;
int i;
//赋值
for (i = 0; i < 20; ++i)
ideq[i] = i;
//输出deque
printf("输出deque中数据:\n");
for (i = 0; i < 20; ++i)
printf("%d ", ideq[i]);
putchar('\n');
//在头尾加入新数据
printf("\n在头尾加入新数据...\n");
ideq.push_back(100);
ideq.push_front(i);
//输出deque
printf("\n输出deque中数据:\n");
for (pos = ideq.begin(); pos != ideq.end(); pos++)
printf("%d ", *pos);
putchar('\n');
//查找
const int FINDNUMBER = 19;
printf("\n查找%d\n", FINDNUMBER);
pos = find(ideq.begin(), ideq.end(), FINDNUMBER);
if (pos != ideq.end()) {
printf("find %d success\n", *pos);
} else
printf("find failed\n");
//在头尾删除数据
printf("\n在头尾删除数据...\n");
ideq.pop_back();
ideq.pop_front();
//输出deque
printf("\n输出deque中数据:\n");
for (pos = ideq.begin(); pos != ideq.end(); pos++)
printf("%d ", *pos);
putchar('\n');
return 0;
}

@ -0,0 +1,33 @@
#include<bits/stdc++.h>
using namespace std;
/*
STL Binary search
使STL便
使
https://www.cnblogs.com/aiguona/p/7281856.html
*/
using namespace std;
int main()
{
int a[100]= {4,10,11,30,69,70,96,100};
int b=binary_search(a,a+9,4);//查找成功返回1
cout<<"在数组中查找元素4结果为"<<b<<endl;
int c=binary_search(a,a+9,40);//查找失败返回0
cout<<"在数组中查找元素40结果为"<<b<<endl;
int d=lower_bound(a,a+9,10)-a;
cout<<"在数组中查找第一个大于等于10的元素位置结果为"<<d<<endl;
int e=lower_bound(a,a+9,101)-a;
cout<<"在数组中查找第一个大于等于101的元素位置结果为"<<e<<endl;
int f=upper_bound(a,a+9,10)-a;
cout<<"在数组中查找第一个大于10的元素位置结果为"<<f<<endl;
int g=upper_bound(a,a+9,101)-a;
cout<<"在数组中查找第一个大于101的元素位置结果为"<<g<<endl;
}

@ -0,0 +1,30 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
set<int>s;
int n;
cin>>n;
for(int i=1; i<=n; i++) {
int x;
cin>>x;
s.insert (x);
}
set<int>::iterator it;
for(it=s.begin (); it!=s.end (); it++) {
printf("%d\n",*it);
}
//s.end()没有值
cout<<"s.begin() "<<*s.begin ()<<endl;
//lower_bound()--返回指向大于(或等于)某值的第一个元素的迭代器
cout<<"lower_buond 3 "<<*s.lower_bound (3)<<endl;
//upper_bound()--返回大于某个值元素的迭代器
cout<<"upper_bound 3 "<<*s.upper_bound (3)<<endl;
//find()--返回一个指向被查找到元素的迭代器
cout<<"find() 3 "<<*s.find (3)<<endl;
cout<<"s.size() "<<s.size ()<<endl;
return 0;
}

@ -0,0 +1,21 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
set<int> s;
s.insert(1);
s.insert(2);
s.insert(3);
s.insert(1);
cout<<"set 的 size 值为 "<<s.size()<<endl;
cout<<"set 的 maxsize的值为 "<<s.max_size()<<endl;
cout<<"set 中的第一个元素是 "<<*s.begin()<<endl;
cout<<"set 中的最后一个元素是:"<<*s.end()<<endl;
s.clear();
if(s.empty()) {
cout<<"set 为空 "<<endl;
}
cout<<"set 的 size 值为 "<<s.size()<<endl;
cout<<"set 的 maxsize的值为 "<<s.max_size()<<endl;
return 0;
}

@ -0,0 +1,12 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
set<int> s;
s.insert(1);
s.insert(2);
s.insert(3);
s.insert(1);
cout<<"set 中 1 出现的次数是 "<<s.count(1)<<endl;
cout<<"set 中 4 出现的次数是 "<<s.count(4)<<endl;
return 0;
}

@ -0,0 +1,18 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
set<int> s;
set<int>::iterator iter;
for(int i = 1 ; i <= 5; ++i) {
s.insert(i);
}
for(iter = s.begin() ; iter != s.end() ; ++iter) {
cout<<*iter<<" ";
}
cout<<endl;
pair<set<int>::const_iterator,set<int>::const_iterator> pr;
pr = s.equal_range(3);
cout<<"第一个大于等于 3 的数是 "<<*pr.first<<endl;
cout<<"第一个大于 3的数是 "<<*pr.second<<endl;
return 0;
}

@ -0,0 +1,27 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
set<int> s;
set<int>::const_iterator iter;
set<int>::iterator first;
set<int>::iterator second;
for(int i = 1 ; i <= 10 ; ++i) {
s.insert(i);
}
//第一种删除
s.erase(s.begin());
//第二种删除
first = s.begin();
second = s.begin();
second++;
second++;
s.erase(first,second);
//第三种删除
s.erase(8);
cout<<"删除后 set 中元素是 ";
for(iter = s.begin() ; iter != s.end() ; ++iter) {
cout<<*iter<<" ";
}
cout<<endl;
return 0;
}

@ -0,0 +1,13 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[] = {1,2,3};
set<int> s(a,a+3);
set<int>::iterator iter;
if((iter = s.find(2)) != s.end())
{
cout<<*iter<<endl;//输出为2
}
return 0;
}

@ -0,0 +1,18 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
int a[] = {1,2,3};
set<int> s;
set<int>::iterator iter;
s.insert(a,a+3);
for(iter = s.begin() ; iter != s.end() ; ++iter) {
cout<<*iter<<" ";
}
cout<<endl;
pair<set<int>::iterator,bool> pr;
pr = s.insert(5);
if(pr.second) {
cout<<*pr.first<<endl;
}
return 0;
}

@ -0,0 +1,44 @@
#include<bits/stdc++.h>
using namespace std;
//数组长度
const int n=10;
/*
2019-10-29
*/
void printArray(int a[n]) {
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout<<endl;
}
int main() {
// 测试数据
int a[n] = { 0, 7, 7, 6, 1, 1, 5, 5, 8, 9 };
//数组长度
int length= (sizeof(a) / sizeof(a[0]));
//去重前打印输出
printArray(a);
//先排序再去重(由小到大:less由大到小greater)
sort(a, a + n, less<int>() );
//开始去重
int n = unique(a, a + length) - a;
//输出去重后的数组
for (int i = 0; i < n; i++)
{
cout << a[i] << " ";
}
return 0;
}

@ -0,0 +1,84 @@
#include<bits/stdc++.h>
using namespace std;
/*
map
2019-10-29
*/
void printMap(map<int, int> _map) {
map<int, int>::iterator iter = _map.begin();
for (; iter != _map.end(); iter++) {
cout << iter->first << ' ' << iter->second << endl;
}
cout << endl;
}
/*
map
2019-10-29
*/
bool isExist(map<int, int> _map, int a) {
map<int, int>::iterator iter = _map.find(a);
if (iter != _map.end()) {
return 1;
}
else {
return 0;
}
}
/*
map
2019-10-29
*/
void deleteMapByKey(map<int, int>& _map, int a) { //注意这里的&表示按引用实参 ,允许函数改变实参的值
//根据键值删除
_map.erase(a);
}
/*
map
2019-10-29
*/
void updateForMap(map<int, int>& _map, int key, int value) { //注意这里的&表示按引用实参 ,允许函数改变实参的值
map<int, int>::iterator iter = _map.find(key);
if (iter != _map.end()) {
iter->second = value;
return;
}
}
int main() {
//字典map
map<int, int> _map;
//插入元素
for (int i = 1; i <= 10; i++) {
pair<int, int> value(i, i);
_map.insert(value);
}
//打印是不是存在数字3
cout << "是否存在数字3" << isExist(_map, 3) << endl;
//尝试删除元素3
deleteMapByKey(_map, 3);
//再次打印是不是存在数字3
cout << "是否存在数字3" << isExist(_map, 3) << endl;
//输出map
cout << "元素修改前的map" << endl;
printMap(_map);
//修改数据
updateForMap(_map, 6, 10);
//输出map
cout << "元素修改后的map" << endl;
printMap(_map);
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

@ -0,0 +1,56 @@
#include <iostream>
#include <cstring>
//全排列代码说明
// https://www.jianshu.com/p/e0de4c9b73f2?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
using namespace std;
//在[from, to]区间中是否有字符与下标为from的字符相等
bool IsSwap(char* from, char* to)
{
char* p;
for(p = from; p < to; p++)
{
if(*p == *to)
return false;
}
return true;
}
void AllPermutation(char* perm, int from, int to)
{
if(from > to)
return;
if(from == to) //打印当前排列
{
static int count = 1; //局部静态变量,用来统计全排列的个数
cout << count++ << ":" << perm;
cout << endl;
}
if(from < to) //用递归实现全排列
{
for(int j = from; j <= to; j++) //第j个字符分别与它后面的字符交换就能得到新的排列
{
if(IsSwap((perm + j), (perm + to)))
{
swap(perm[j], perm[from]);
//cout<<0;
AllPermutation(perm, from + 1, to);
//cout<<1;
swap(perm[j], perm[from]);
//cout<<2;
}
}
}
}
int main()
{
char str[100];
cin >> str;
AllPermutation(str, 0, strlen(str) - 1);
return 0;
}

@ -0,0 +1,14 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
//注意:这个数组的数字要先排好顺序,由小到大,否则只输出比现在大的全排列!
int num[5]= {3,1,2,4,5};
//快速排序
sort(num, num+5);
//输出全排列
do {
cout<<num[0]<<" "<<num[1]<<" "<<num[2]<<" "<<num[3]<<" "<<num[4]<<endl;
} while(next_permutation(num,num+5));
return 0;
}

@ -0,0 +1,38 @@
#include<bits/stdc++.h>
using namespace std;
int a[10], book[10], n;
//全排列算法运用深度优先搜索dfs
void dfs(int step)
{
int i;
if (step == n + 1) //如果站在第n+1个箱子前则表示前n个箱子已经排列好
{
for (i = 1; i <= n; i++) //输出一种排列1-n号箱子中的扑克牌编号
{
cout << a[i];
}
cout << endl;
return; //返回之前的一步最近一次调用dfs函数的地方
}
//当站在第step个箱子面前应该放什么牌
//依次实验1、2、3、4.....是否可行
for (i = 1; i <= n; i++)
{
//判断扑克牌i是否还在手上
if (book[i] == 0)
{
a[step] = i; //将第i号扑克牌放到第step个箱子中
book[i] = 1; //将book[i]设置为1则表示第i张扑克牌不在手中
dfs(step + 1); //第step个箱子放好后走到下一个箱子
book[i] = 0; //同时收回刚才尝试的扑克牌
}
}
return;
}
int main() {
n=3;
dfs(1);
return 0;
}

@ -0,0 +1,20 @@
#include<bits/stdc++.h>
using namespace std;
//C++STL中全排列函数next_permutation的使用
// https://blog.csdn.net/ac_gibson/article/details/45308645
int main()
{
int a[3] = { 3,1,2 };
//快速排序
sort(a, a + 3);
//全排列
do
{
cout << a[0] << a[1] << a[2] << endl;
} while (next_permutation(a, a + 3));
return 0;
}

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29306.81
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShjCppStudy", "ShjCppStudy.vcxproj", "{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Debug|x64.ActiveCfg = Debug|x64
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Debug|x64.Build.0 = Debug|x64
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Debug|x86.ActiveCfg = Debug|Win32
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Debug|x86.Build.0 = Debug|Win32
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Release|x64.ActiveCfg = Release|x64
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Release|x64.Build.0 = Release|x64
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Release|x86.ActiveCfg = Release|Win32
{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9C8E3F9E-D637-4138-816C-B43DBD8F12D2}
EndGlobalSection
EndGlobal

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DFS实现全排列.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{26EB7DDD-AA76-44F3-8780-67869B7CF8DD}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ShjCppStudy</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DFS实现全排列.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>

@ -0,0 +1,39 @@
#include<bits/stdc++.h>
using namespace std;
//打印数组全部元素
void prt(int arr[], int end) {
for (int i = 0; i <= end; ++i) {
printf("%d", arr[i]);
}
printf("\n");
}
//全排列 c++实现
//https://blog.csdn.net/u013309870/article/details/68941284
//https://blog.csdn.net/jiaobuchong/article/details/85369970
//https://www.cnblogs.com/kiritozhj/p/10501470.html
// https://blog.csdn.net/sofia_m/article/details/78865892
void perm(int arr[], int begin, int end) {
//递归出口,结束时打印结果
if (begin == end) {
prt(arr, end);
return;
}
//还没到出口时,就需要进行递归的递归体开发
for (int i = begin; i <= end; ++i) {
//交换两个元素值
swap(arr[begin], arr[i]);
//递归体
perm(arr, begin + 1, end);
//恢复原状
swap(arr[begin], arr[i]);
}
}
int main()
{
int arr[3] = { 3,1,2 };
perm(arr, 0, 2);
}

@ -0,0 +1,37 @@
#include<bits/stdc++.h>
using namespace std;
//打印数组全部元素
void prt(int arr[], int end) {
for (int i = 0; i <= end; ++i) {
printf("%d", arr[i]);
}
printf("\n");
}
void perm(int arr[], int len) {
if (len < 2) return;
int i, j, temp;
while(1) {
//输出当前序列
prt(arr, len - 1);
i = j = len - 1;
//向前查找第一个变小的元素
while (i > 0 && arr[i] < arr[i - 1]) --i;
temp = i;
if (i == 0) break;
//先后查找第一个比arr[i-1]大的元素
while (temp + 1 < len && arr[temp + 1] > arr[i - 1]) ++temp;
swap(arr[i - 1], arr[temp]); //交换两个值
reverse(arr + i, arr + len); //逆序
};
}
int main()
{
int arr[3] = { 3,1,2 };
//快速排序
sort(arr, arr + 3);
//输出全排列
perm(arr,3);
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save