Ver código fonte

save section3-7

tangs 7 anos atrás
pai
commit
fdf4a9345c
2 arquivos alterados com 17 adições e 8 exclusões
  1. 7 0
      section3-7/CMakeLists.txt
  2. 10 8
      section3-6/main.cpp

+ 7 - 0
section3-7/CMakeLists.txt

@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.6)
+project(section3_7)
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+
+set(SOURCE_FILES main.cpp)
+add_executable(section3_7 ${SOURCE_FILES})

+ 10 - 8
section3-6/main.cpp

@@ -7,15 +7,17 @@ struct Box {
     int Bi;
 };
 
-bool judge(int V, int maxAi, int maxBi, int allAi) {
-    if (maxAi > maxBi){
-        return false;
-    }
-    if (allAi > V){
+bool compare(Box a, Box b) {
+    return a.Bi > b.Bi;
+}
+
+bool judge(int V, int N, int maxAi, int maxBi, Box *boxes) {
+    if (maxAi > maxBi) {
         return false;
     }
-    if(maxBi > V){
-        return false;
+    sort(boxes, boxes + N, compare);
+    for (int i = 0; i < N; i++) {
+        
     }
     return true;
 }
@@ -42,7 +44,7 @@ int main() {
                 allAi += box.Ai;
                 boxes[j] = box;
             }
-            cout << (judge(V, maxAi, maxBi, allAi) ? "YES" : "NO") << endl;
+            cout << (judge(V, N, maxAi, maxBi, boxes) ? "YES" : "NO") << endl;
             free(boxes);
         }
     }