考覈事後感受本身的學習方式有不少問題。平時周任務不能看着博客就模仿着寫出來,或者照搬別人的思路,應該有充分的理解,保證本身不看別人的博客時,本身也能夠獨立寫出來。平時要提升效率。比賽時要加快速度,理清思路。注意細節!node
三道原題。ios
網線切割ide
二分查找經典題目函數
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #define inf 0x3f3f3f3f 6 using namespace std; 7 const int maxn=100; 8 int n, k ; 9 double a[maxn]; 10 bool check(double x){//檢查是否達到須要的數量 11 int ans=0; 12 for(int i=0; i<n; i++){ 13 ans+=a[i]/x; 14 } 15 if(ans>=k) return true; 16 else return false; 17 } 18 int main(){ 19 cin >> n >> k ; 20 for(int i=0; i<n; i++) 21 cin >> a[i]; 22 int l=0, r=inf; 23 for(int i=0; i<100; i++){//進行二分,100是次數,從而保證精度 24 double mid=(l+r)/2.0; 25 if(check(mid)) l=mid; 26 else r=mid; 27 } 28 printf("%.2f",floor(r*100)/100);//要小於0.01m; floor向下取整函數 29 //頭文件#include<cmath> 30 return 0; 31 } 32 /* 33 4 11 34 5.39 35 8.02 36 7.43 37 4.57 38 */
八皇后(復刻)學習
dfs經典題目spa
1 #include<cstdio> 2 #include<iostream> 3 #define inf 0x3f3f3f3f 4 using namespace std; 5 const int maxn=105;//注意範圍要足夠大 6 int a[maxn], b[maxn],c[maxn],d[maxn]; 7 int n,ans=0; 8 void print(){ 9 ans++; 10 if(ans<=3)//保證輸出三個解 11 { 12 for(int k=1; k<=n; k++) 13 cout << a[k] << " " ; 14 cout << endl ; 15 } 16 } 17 void dfs(int i){ 18 if(i==n+1) //尋找完全部皇后輸出其縱座標 19 { 20 print();//自定義輸出函數 21 return ; 22 } 23 else 24 { 25 for(int j=1; j<=n; j++)//尋找可放置位置 26 { 27 if(b[j]==0&&c[i+j]==0&&d[i-j+n]==0)// 是否符合條件 28 { 29 a[i]=j;//佔領位置 30 b[j]=1;//佔領縱列 31 c[i+j]=1;//佔領對角線(左下-右上) 32 d[i-j+n]=1;//佔領對角線(左上-右下) 33 dfs(i+1);//尋找下一個皇后座標 34 b[j]=0;//回溯 35 c[i+j]=0; 36 d[i-j+n]=0; 37 } 38 } 39 } 40 return ; 41 } 42 int main(){ 43 cin >> n ; 44 dfs(1);//從第一個皇后 開始尋找座標 45 cout << ans ;//輸出 46 return 0; 47 } 48 //八皇后問題 僅輸出前三個解的座標以及總共解的個數
迷宮code
經典bfs題目(+拐彎限制問題)blog
1 //注意題目陷阱 例:輸入時的 行/列 2 //拐彎問題能夠在肯定一個方向後一直走下去直到不能走或到終點 3 4 #include<cstdio> 5 #include<cstring> 6 #include<iostream> 7 #include<queue> 8 #define inf 0x3f3f3f3f 9 using namespace std; 10 const int maxn=105; 11 int t, m, n; 12 struct node{ 13 int x, y; 14 int dir; 15 }st,ed,ss,tt; 16 int turn,fx,fy,sx,sy; 17 int dx[]={-1,1,0,0},dy[]={0,0,-1,1}; 18 bool vis[maxn][maxn]; 19 char maps[maxn][maxn]; 20 int bfs(){ 21 queue <node> que; 22 st.dir=-1; 23 vis[ss.x][ss.y]=true; 24 que.push(st); 25 while(!que.empty()) 26 { 27 ss=que.front(); 28 que.pop(); 29 30 if(ss.x==ed.x&&ss.y==ed.y&&ss.dir<=turn) return 1;//起點即終點進行判斷 31 for(int i=0; i<4; i++) 32 { 33 tt.x=ss.x+dx[i]; 34 tt.y=ss.y+dy[i]; 35 tt.dir=ss.dir+1;//已經肯定了第一次的方向將-1變0 36 if(tt.dir>turn) continue; 37 while(tt.x>=1&&tt.x<=m&&tt.y>=1&&tt.y<=n&&maps[tt.x][tt.y]!='*') 38 {//符合基本條件 39 if(!vis[tt.x][tt.y])//? 40 { 41 que.push(tt); 42 vis[tt.x][tt.y]=true; 43 } 44 tt.x+=dx[i]; 45 tt.y+=dy[i];//繼續走下去 46 if(tt.x==ed.x&&tt.y==ed.y&&tt.dir<=turn) return 1; 47 } 48 } 49 } 50 return 0; 51 } 52 int main(){ 53 cin >> t ; 54 while(t--) 55 { 56 cin >> m >> n ; 57 for(int i=1; i<=m; i++) 58 for(int j=1; j<=n; j++) 59 scanf(" %c", &maps[i][j]); 60 cin>>turn>>st.y>>st.x>>ed.y>>ed.x;//!!!注意細節 注意哪一個是行哪一個是列 61 if(bfs()) printf("yes\n"); 62 else printf("no\n"); 63 memset(vis,0,sizeof(vis)); 64 } 65 66 return 0; 67 } 68 /* 69 2 70 5 5 71 ...** 72 *.**. 73 ..... 74 ..... 75 *.... 76 1 1 1 1 3 77 5 5 78 ...** 79 *.**. 80 ..... 81 ..... 82 *.... 83 2 1 1 1 3 84 */
no
yes
2020-12-19 21:09:31ci
有錯誤的地方1請大佬們多多指點!博客