✅ P7910 76pts (TLE)
This commit is contained in:
		| @@ -23,4 +23,5 @@ add_executable(Playground | ||||
|         take-most-space-element/main.cc | ||||
|         walking-in-maze/main.cc | ||||
|         network-connection/main.cpp | ||||
|         eating-snake/main.cc) | ||||
|         eating-snake/main.cc | ||||
|         insert-sort/main.cc) | ||||
|   | ||||
| @@ -4,7 +4,7 @@ | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| //#define ENABLE_LOG | ||||
| #define ENABLE_LOG | ||||
|  | ||||
| struct snake { | ||||
|     int id; | ||||
| @@ -29,8 +29,8 @@ bool sort_by_id(snake a, snake b) { | ||||
|     return b.id > a.id; | ||||
| } | ||||
|  | ||||
| void eat(vector<snake> &vec, bool skip_sort = false) { | ||||
|     if (vec.size() < 2) return; | ||||
| bool eat(vector<snake> &vec, bool skip_sort = false, int initial_id = 0) { | ||||
|     if (vec.size() < 2) return true; | ||||
|     if (!skip_sort) { | ||||
|         sort(vec.begin(), vec.end()); | ||||
|     } | ||||
| @@ -42,8 +42,8 @@ void eat(vector<snake> &vec, bool skip_sort = false) { | ||||
|     } | ||||
| #endif | ||||
|  | ||||
|     if (!(vec[0] >= vec[vec.size() - 1])) { | ||||
|         return; | ||||
|     if (!(vec[initial_id] >= vec[vec.size() - 1])) { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     // If this snake ate the last snake | ||||
| @@ -53,7 +53,7 @@ void eat(vector<snake> &vec, bool skip_sort = false) { | ||||
|     printf("%d gonna to eat %d\n", curr.id, last.id); | ||||
| #endif | ||||
|     vec.pop_back(); | ||||
|     vec[0].power -= last.power; | ||||
|     vec[initial_id].power -= last.power; | ||||
|     sort(vec.begin(), vec.end()); | ||||
|     if (vec[0].id != curr.id) { | ||||
|         bool will_be_eaten = false; | ||||
| @@ -86,7 +86,6 @@ void eat(vector<snake> &vec, bool skip_sort = false) { | ||||
|                 } | ||||
|             } | ||||
|             vec.push_back(last); | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
							
								
								
									
										6
									
								
								insert-sort/data.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								insert-sort/data.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| 3 4 | ||||
| 3 2 1 | ||||
| 2 3 | ||||
| 1 3 2 | ||||
| 2 2 | ||||
| 2 3 | ||||
							
								
								
									
										38
									
								
								insert-sort/main.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								insert-sort/main.cc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| // The question want me to impl a sort by my self | ||||
| // But absolutely not | ||||
|  | ||||
| #include <iostream> | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| int main() { | ||||
|     int n, Q; | ||||
|     cin >> n >> Q; | ||||
|     int arr[n + 5]; | ||||
|  | ||||
|     for (int i = 1; i <= n; i++) { | ||||
|         cin >> arr[i]; | ||||
|     } | ||||
|  | ||||
|     for (int i = 0; i < Q; i++) { | ||||
|         int op; | ||||
|         cin >> op; | ||||
|         if (op == 1) { | ||||
|             int x, v; | ||||
|             cin >> x >> v; | ||||
|             arr[x] = v; | ||||
|         } else { | ||||
|             int xn; | ||||
|             cin >> xn; | ||||
|             int it = arr[xn]; | ||||
|             int pos = n; | ||||
|             for (int j = 1; j < xn; j++) { | ||||
|                 if (arr[j] > it) pos--; | ||||
|             } | ||||
|             for (int j = xn + 1; j <= n; j++) { | ||||
|                 if (arr[j] >= it) pos--; | ||||
|             } | ||||
|             cout << pos << endl; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user