From e4f5a0f5383b6b36a53cb38ec0c6342cc379b141 Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:26:07 +0800 Subject: [PATCH 01/14] Create p02_isPrime.cpp --- level1/p02_isPrime/p02_isPrime.cpp | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 level1/p02_isPrime/p02_isPrime.cpp diff --git a/level1/p02_isPrime/p02_isPrime.cpp b/level1/p02_isPrime/p02_isPrime.cpp new file mode 100644 index 00000000..953e3f93 --- /dev/null +++ b/level1/p02_isPrime/p02_isPrime.cpp @@ -0,0 +1,40 @@ +#include +#include +#define ll long long +using namespace std; +const int maxn=100000,N1=maxn+5; + +int pr[N1],cnt; +bool vis[N1]; +void get_prime() +{ + for(int i=2;i<=maxn;i++) + { + if(!vis[i]) pr[++cnt]=i; + for(int j=1;j<=cnt&&i*pr[j]<=maxn;j++) + { + vis[i*pr[j]]=1; + if(i%pr[j]==0) break; + } + } +} +int check(ll x) +{ + ll m=sqrt(x); + for(int j=1;pr[j]<=m&&j<=cnt;j++) + if(x%pr[j]==0) return 0; + return 1; +} + +ll n; + +int main() +{ + scanf("%lld",&n); + if(n<=1){ puts("bad input"); return 0; } + get_prime(); + int flag=check(n); + if(!flag) puts("NO"); else puts("YES"); + return 0; +} + From ed5c7726a160ddea72fef2c54c06326704fd00d4 Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:26:34 +0800 Subject: [PATCH 02/14] Create p03_Diophantus.cpp --- level1/p03_Diophantus/p03_Diophantus.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 level1/p03_Diophantus/p03_Diophantus.cpp diff --git a/level1/p03_Diophantus/p03_Diophantus.cpp b/level1/p03_Diophantus/p03_Diophantus.cpp new file mode 100644 index 00000000..95f4ae68 --- /dev/null +++ b/level1/p03_Diophantus/p03_Diophantus.cpp @@ -0,0 +1,16 @@ +#include +#include +#define dd double +#define ll long long +using namespace std; +const int maxn=100000,N1=maxn+5; + + +int main() +{ + //(1/6+1/12+1/7)x+5+1/2x+4=x + dd x=(5.0+4.0)/(1.0-1.0/2-1.0/6-1.0/7-1.0/12); + printf("%.0lf\n",x); + return 0; +} + From c4509f6896e7681ef16884e160752e956ff5b86b Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:27:06 +0800 Subject: [PATCH 03/14] Create p04_narcissus.cpp --- level1/p04_ narcissus/p04_narcissus.cpp | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 level1/p04_ narcissus/p04_narcissus.cpp diff --git a/level1/p04_ narcissus/p04_narcissus.cpp b/level1/p04_ narcissus/p04_narcissus.cpp new file mode 100644 index 00000000..9ebe8c46 --- /dev/null +++ b/level1/p04_ narcissus/p04_narcissus.cpp @@ -0,0 +1,28 @@ +#include +#include +#define dd double +#define ll long long +using namespace std; +const int maxn=100000,N1=maxn+5; + +int a[2]; +void check(int x) +{ + int tx=x,tot=0; + for(int i=0;i<=2;i++) + { + a[i]=tx%10, tx/=10; + tot+=a[i]*a[i]*a[i]; + } + if(tot==x) printf("%d\n",x); +} + +int main() +{ + for(int i=100;i<=999;i++) + { + check(i); + } + return 0; +} + From a0c5789e6297080dc0fa5343a35fa66ca83493b1 Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:27:34 +0800 Subject: [PATCH 04/14] Create p05_allPrimes.cpp --- level1/p05_allPrimes/p05_allPrimes.cpp | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 level1/p05_allPrimes/p05_allPrimes.cpp diff --git a/level1/p05_allPrimes/p05_allPrimes.cpp b/level1/p05_allPrimes/p05_allPrimes.cpp new file mode 100644 index 00000000..666a1f49 --- /dev/null +++ b/level1/p05_allPrimes/p05_allPrimes.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#define dd double +#define ll long long +using namespace std; +const int maxn=1000,N1=maxn+5; + +clock_t st,ed; +int pr[N1],cnt; +bool vis[N1]; +void get_prime() +{ + for(int i=2;i<=maxn;i++) + { + if(!vis[i]) pr[++cnt]=i, printf("%d ",i); + for(int j=1;j<=cnt&&i*pr[j]<=maxn;j++) + { + vis[i*pr[j]]=1; + if(i%pr[j]==0) break; + } + } + puts(""); +} + +int main() +{ + st=clock(); + get_prime(); + ed=clock(); + printf("%.7lfs\n",(double)(ed-st)/CLOCKS_PER_SEC); + //Time complexity:O(n) + return 0; +} + From ca625eebd2f070f94ec0ec33b86cd995b363696a Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:28:03 +0800 Subject: [PATCH 05/14] Create p06_Goldbach.cpp --- level1/p06_Goldbach/p06_Goldbach.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 level1/p06_Goldbach/p06_Goldbach.cpp diff --git a/level1/p06_Goldbach/p06_Goldbach.cpp b/level1/p06_Goldbach/p06_Goldbach.cpp new file mode 100644 index 00000000..034175c2 --- /dev/null +++ b/level1/p06_Goldbach/p06_Goldbach.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#define dd double +#define ll long long +using namespace std; +const int maxn=100,N1=maxn+5; + +clock_t st,ed; +int pr[N1],cnt; +bool vis[N1]; +void get_prime() +{ + for(int i=2;i<=maxn;i++) + { + if(!vis[i]) pr[++cnt]=i; //printf("%d ",i); + for(int j=1;j<=cnt&&i*pr[j]<=maxn;j++) + { + vis[i*pr[j]]=1; + if(i%pr[j]==0) break; + } + } + // puts(""); +} +void check(int x) +{ + for(int i=2;i+2<=x;i++) if(!vis[i]&&!vis[x-i]) + { printf("%d:%d %d\n",x,i,x-i); return; } + printf("%d:failed\n",x); +} + +int main() +{ + // Goldbach conjecture: + // every even number greater than 2 is able to be represented as the sum of two primes + get_prime(); + for(int i=4;i<=maxn;i+=2) check(i); + // Time complexity : O(n^2) + return 0; +} + From ceffcbf6eaa657afbec932a997fa9a1c7e29d1dc Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:28:35 +0800 Subject: [PATCH 06/14] Create p07_encrypt_decrypt.cpp --- .../p07_encrypt_decrypt.cpp | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 level1/p07_encrypt_decrypt/p07_encrypt_decrypt.cpp diff --git a/level1/p07_encrypt_decrypt/p07_encrypt_decrypt.cpp b/level1/p07_encrypt_decrypt/p07_encrypt_decrypt.cpp new file mode 100644 index 00000000..9cc1960b --- /dev/null +++ b/level1/p07_encrypt_decrypt/p07_encrypt_decrypt.cpp @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#define dd double +#define ll long long +using namespace std; +const int maxn=100,N1=maxn+5,base=63; + +// base64: +char encx(int x) +{ + x=x&base; + if(0<=x&&x<=25) return x+'A'; + if(26<=x&&x<=51) return x-26+'a'; + if(52<=x&&x<=61) return x-52+'0'; + if(x==62) return '+'; else return '/'; +} +int decx(char x) +{ + if('A'<=x&&x<='Z') return x-'A'; + if('a'<=x&&x<='z') return x-'a'+26; + if('0'<=x&&x<='9') return x-'0'+52; + if(x=='+') return 62; else return 63; +} +int encrypt(char *s,char *enc,int len) +{ + int n=0,tmp,i; + for(i=0;i>=6; + enc[n++]=encx(tmp); tmp>>=6; + enc[n++]=encx(tmp); tmp>>=6; + enc[n++]=encx(tmp); + } + if(len%3==1) enc[n-1]='=', enc[n-2]='='; + else if(len%3==2) enc[n-1]='='; + return n; +} +void decrypt(char *enc,char *s) +{ + int tmp,y,len=strlen(enc); + if(enc[len-1]=='=') enc[len-1]='A'; if(enc[len-2]=='=') enc[len-2]='A'; + for(int i=0,j;i Date: Tue, 16 Mar 2021 20:29:00 +0800 Subject: [PATCH 07/14] Create p08_hanoi.cpp --- level1/p08_hanoi/p08_hanoi.cpp | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 level1/p08_hanoi/p08_hanoi.cpp diff --git a/level1/p08_hanoi/p08_hanoi.cpp b/level1/p08_hanoi/p08_hanoi.cpp new file mode 100644 index 00000000..1ae23768 --- /dev/null +++ b/level1/p08_hanoi/p08_hanoi.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#define dd double +#define ll long long +#define ull unsigned long long +using namespace std; +const int maxn=100,N1=maxn+5,base=63; + +int n; +int tot=0; +void mov(int dep,int st,int via,int ed) +{ + if(dep>1) mov(dep-1,st,ed,via); + printf("step %d: %d %d -> %d\n",++tot,dep,st,ed); + if(dep>1) mov(dep-1,via,st,ed); +} + +int main() +{ + freopen("a.out","w",stdout); + scanf("%d",&n); + int A=1,B=2,C=3; + mov(n,A,B,C); + return 0; +} + + +// ull f[N1]; + +// 题解: +// 1. 考虑递推(或归纳), 设A柱子为起始柱,B柱子为辅助柱,C柱子为目标柱 +// 假设我们已经求解出A柱子上有i个圆盘时的答案,现在需要求解有i+1个圆盘时的答案; +// 第i+1个圆盘在移动前必须保证如下条件:A中最上面的圆盘是i+1,B应该放置1~i的所有圆盘,C是空柱子 +// 然后再把B当做起始柱,A当做辅助柱,把放置在B上的1~i的所有圆盘依次挪到C +// 可得递推式:f[i]=f[i-1]*2+1, f[1]=1 +// n=64可以用递推轻松求解(注意要使用unsigned long long) From a4e7c96ccea054c199a9b290331c661cb30f4a87 Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 16 Mar 2021 20:30:12 +0800 Subject: [PATCH 08/14] Create p09_maze.cpp --- level1/p09_maze/p09_maze.cpp | 256 +++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 level1/p09_maze/p09_maze.cpp diff --git a/level1/p09_maze/p09_maze.cpp b/level1/p09_maze/p09_maze.cpp new file mode 100644 index 00000000..b770806a --- /dev/null +++ b/level1/p09_maze/p09_maze.cpp @@ -0,0 +1,256 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#define dd double +#define ll long long +#define ull unsigned long long +using namespace std; + +// // 生成迷宫:生成树算法 +// // 我的做法:随机边权然后最小生成树 +int n,m,cte; +struct EDGE{ +int x,y,w; +friend bool operator < (const EDGE &s1,const EDGE &s2) +{ + return s1.w=1 && x=1 && y=1 && x+fx[to]=1 && y+fy[to] Date: Fri, 9 Apr 2021 16:08:44 +0800 Subject: [PATCH 09/14] Create p10_pushBoxes.h --- p10_pushBoxes.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 p10_pushBoxes.h diff --git a/p10_pushBoxes.h b/p10_pushBoxes.h new file mode 100644 index 00000000..02d8f927 --- /dev/null +++ b/p10_pushBoxes.h @@ -0,0 +1,14 @@ +#include "p10_push.cpp" + +int checkx(int x,int y); +int id(int x,int y); +int checkok(int x,int y); +void initconsolveScreenBuffer(); +int show(HANDLE hout,int &x,int &y,int to); +int get_toward(); +void setcolor(HANDLE hCon,unsigned short ForeColor,unsigned short BackGroundColor); +void initconsolveScreenBuffer(int &x,int &y); +void print_unique(HANDLE hout,int i,int y,int color); +void put_str(HANDLE hout,int color,char *s,int type); + + From 8294a72902b457b51ef612e3b83b04a89dc136e3 Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Fri, 9 Apr 2021 16:15:35 +0800 Subject: [PATCH 10/14] Create p10_pushBoxes.cpp --- p10_pushBoxes.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 p10_pushBoxes.cpp diff --git a/p10_pushBoxes.cpp b/p10_pushBoxes.cpp new file mode 100644 index 00000000..3288dc92 --- /dev/null +++ b/p10_pushBoxes.cpp @@ -0,0 +1,44 @@ +#include "p10_push.h" + +int main() +{ + // init_hard_version(); + int to=0,now=1,x,y; //初始化输出一次 + while(task<=4) + { + switch(task) + { + case 1: freopen("round1.in","r",stdin); break; + case 2: freopen("round2.in","r",stdin); break; + case 3: freopen("round3.in","r",stdin); break; + case 4: freopen("round4.in","r",stdin); break; + } + initconsolveScreenBuffer(x,y); Score=0; + fclose(stdin); + now=1; to=5; show(output[now],x,y,to); now^=1; + while(to=get_toward()) + { + show(output[now],x,y,to); + if(Score==End) + { n=n; break; } + now^=1; + } + LPDWORD num=0; + // coord.Y=n+3; + WriteConsoleA(output[now],"\n",1,num,NULL); + put_str(output[now],FG|FB|FI,"Congratulations!\n",1); + if(task==4) break; + Sleep(3000); + task++; + } + put_str(output[now],FG|FB|FI,"YOU WIN!!!\n",1); + Sleep(1000000); + return 0; +} + +// #:墙 +// @:玩家位置 +// $:箱子 +// ?:目标地点 +// %:已经得分 + From 40abbf7f21d262488c70cb748cff39b2b7580021 Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Fri, 9 Apr 2021 16:16:04 +0800 Subject: [PATCH 11/14] Create p10_push.cpp --- p10_push.cpp | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 p10_push.cpp diff --git a/p10_push.cpp b/p10_push.cpp new file mode 100644 index 00000000..9e118d40 --- /dev/null +++ b/p10_push.cpp @@ -0,0 +1,190 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#define FG FOREGROUND_GREEN +#define FR FOREGROUND_RED +#define FB FOREGROUND_BLUE +#define FI FOREGROUND_INTENSITY +#define dd double +#define ll long long +#define ull unsigned long long +using namespace std; + +int n,m,Score,End,step; +HANDLE output[2]; +COORD coord = {0,0}; +DWORD bytes = 0; +int checkx(int x,int y) +{ + if(x>=1 && x=1 && y=1 && x=1 && y Date: Tue, 13 Apr 2021 19:43:34 +0800 Subject: [PATCH 12/14] Create p11_linkedList.cpp --- p11_linkedList.cpp | 223 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 p11_linkedList.cpp diff --git a/p11_linkedList.cpp b/p11_linkedList.cpp new file mode 100644 index 00000000..047d63c5 --- /dev/null +++ b/p11_linkedList.cpp @@ -0,0 +1,223 @@ +#include +#include +#include +#include +#define dd double +#define ll long long +#define ull unsigned long long +// #include "p11_linkedList.h" +using namespace std; +const int N1=105; + +int n, tot; +struct node{ +int val; node *nxt; +}; +node *head; + +int get_command(); +node* createnode(int x); +void releasenode(node* now); +node* insert(int pos,int x); +void del(); +void DEL(int pos); +void print(int type); +node* inverse(); +int find_first(int w); +int find_nxt(int pos,int w); + +void ins() +{ + system("cls"); + print(0); + puts("Please input new point's position and its value."); + int pos, w; + scanf("%d %d",&pos,&w); + insert(pos,w); +} +void del() +{ + system("cls"); + print(0); + puts("Please input the position where you want to delete."); + int pos; + scanf("%d",&pos); + DEL(pos); +} +void abnor() +{ + puts(""); + puts("Press [0] to continue..."); + int to; + while(1) + { + to=get_command(); + if(to==0) break; + } +} +int find1() +{ + system("cls"); + puts("Please input the value you want to find."); + int pos,w; scanf("%d",&w); + pos = find_first(w); + printf("%d",pos); + abnor(); + return pos; +} +int now_w; +int findn(int st) +{ + system("cls"); + puts("Please input the value you want to find."); + int pos,w; + if(st==-1){ + pos=-1; puts("Please redirect the start position by press [5] in your next command."); + // if(now_w == w) pos=-1; else { scanf("%d",&w); pos = find_nxt(st,w); now_w = w; } + }else{ scanf("%d",&w); pos = find_nxt(st,w); now_w = w; } + printf("%d",pos); + abnor(); + return pos; +} + +int main() +{ + // freopen("a.in","r",stdin); + printf("Plz input the size of your linkedlist:"); + scanf("%d",&n); + puts("Plz input the elements in order in your linkedlist:"); + puts("The last element will be linked with the first element."); + head = new node ((node){0,NULL}); + for(int i=0;i1) now = nxt; + } +} +node* createnode(int x) +{ + node *buf = new node ((node){x,NULL}); + return buf; +} +node* insert(int pos,int x) +{ + node* now=head; + if((*now).nxt==NULL){ (*now).val=x; (*now).nxt=now; tot++; return now; } //原链表没有元素 + pos--; + for(;pos;now=(*now).nxt,pos--); + node *nxt = (*now).nxt, *cur = createnode(x); + (*now).nxt = cur; (*cur).nxt = nxt; + tot++; + return cur; +} +void DEL(int pos) +{ + node* now=head; + if(pos==1) pos=tot; else pos--; + for(;pos>1;now=(*now).nxt,pos--); + node *cur = (*now).nxt; + (*now).nxt = (*cur).nxt; + delete cur; + tot--; +} +void print(int type) +{ + node *now; now=head; int cnt=tot; + for(;cnt;cnt--,now=(*now).nxt) + { + printf("%d ",(*now).val); + } + if(type==0) puts(""); + if(type==1) abnor(); +} +node* inverse() +{ + node *cur = createnode((*head).val), *now, *tmp, *nxt, *st; + (*cur).nxt = cur; + now = head; st = cur; + int cnt = tot; + for(;cnt;cnt--,now=(*now).nxt) + { + nxt = (*now).nxt; + if(cnt!=1) tmp = createnode((*nxt).val); else tmp = st; + (*tmp).nxt = cur; + cur = tmp; + } + releasenode(head); + head = cur; + print(1); + return cur; +} +int find_first(int w) +{ + node* now = head; int cnt=1; + for(;cnt<=tot;cnt++,now=(*now).nxt) + { + if((*now).val==w) break; + } + if(cnt==tot+1) return -1; + return cnt; +} +int find_nxt(int pos,int w) //pos之后的第一个w值 +{ + node* now = head; int cnt=pos; + for(;cnt;now=(*now).nxt,cnt--); cnt=pos+1; + for(;cnt<=tot;cnt++,now=(*now).nxt) + { + if((*now).val==w) break; + } + if(cnt==tot+1) return -1; + return cnt; +} From 9681f6e8ea8b5de0dcdd9cd40cd645c4910611d7 Mon Sep 17 00:00:00 2001 From: guapisolo <48857426+guapisolo@users.noreply.github.com> Date: Tue, 13 Apr 2021 19:44:16 +0800 Subject: [PATCH 13/14] Create p12_warehouse.cpp --- p12_warehouse.cpp | 165 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 p12_warehouse.cpp diff --git a/p12_warehouse.cpp b/p12_warehouse.cpp new file mode 100644 index 00000000..7129c06b --- /dev/null +++ b/p12_warehouse.cpp @@ -0,0 +1,165 @@ +#include +#include +#include +#include +#define dd double +#define ll long long +#define ull unsigned long long +using namespace std; +const int N1=10005; + +int n,m; +struct Ware{ +char name[40]; +int len,num; +}a[N1]; + +// 1. 实现如下的菜单(按数字选择菜单功能): +// - 显示存货列表 // 1 +// - 入库 // 2 +// - 出库 // 3 +// - 退出程序 // 0 +// 1. 实现菜单对应功能(需记录货物的型号、数量等信息); +// 1. 程序启动时从文件中读取当前库存数据,退出时保存库存数据; + +int get_command() +{ + int input=getch(),to; + switch(input) + { + case '1': to=1; break; + case '2': to=2; break; + case '3': to=3; break; + case '0': to=4; break; + default : to=-1; break; + } + return to; +} + +int idx(char c){ + if(c=='-') return 0; if(c=='.') return 1; + if('A'<=c&&c<='Z') return c-'A'+2; + if('a'<=c&&c<='z') return c-'a'+28; + if('0'<=c&&c<='9') return c-'0'+55; +} //' '之后的 +int id[N1]; +struct Trie{ +int ch[N1*40][64],id[N1],tot; +int findx(char *s,int len) +{ + int x=0,c; + for(int i=0;i Date: Tue, 22 Jun 2021 15:32:49 +0800 Subject: [PATCH 14/14] Create p01_runningLetter.cpp --- p01_runningLetter.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 p01_runningLetter.cpp diff --git a/p01_runningLetter.cpp b/p01_runningLetter.cpp new file mode 100644 index 00000000..38ad5da8 --- /dev/null +++ b/p01_runningLetter.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +using namespace std; + + +char str[]="sto NamelessOIer orz"; + +int main() +{ + int now=0,len=20,type=1; + while(1) + { + system("cls"); + for(int i=1;i<=now;i++) printf(" "); + for(int i=0;i