标签:else 剪枝 coder esc iostream hoc mem ace als
思路:
刚开始的时候,如果骨头数量足够多,没条狗都有骨头吃,可以直接 m-=n。如果不大于,那就剪枝出去了
当骨头足够多的时候,按照时间的路线,吃的快的狗总是先吃。如果骨头没了,over
1 /* 2 Name: 3 Copyright: 4 Author: 5 Date: 2018/5/7 20:13:00 6 Description: 7 */ 8 #include <algorithm> 9 #include <iostream> 10 #include <cstdio> 11 #include <cstring> 12 using namespace std; 13 int arr[105]; 14 int speed[105]; 15 int main() 16 { 17 int m, n, x; 18 ios::sync_with_stdio(false); 19 while (cin>>m>>n>>x) { 20 memset(arr, 0, sizeof(arr)); 21 memset(speed, 0, sizeof(speed)); 22 for (int i=0; i<n; i++) cin>>speed[i]; 23 sort (speed, speed+n); 24 for (int i=1;i <= x; i++) { 25 if (m <= 0) break; 26 for (int j=0; j<n; j++) { 27 if (m <= 0) break; 28 if (arr[j] == 0) m--; 29 if (i % speed[j] == 0) { 30 arr[j] = 0; 31 } else arr[j] = 1; 32 } 33 } 34 int sum = 0; 35 for (int i=0; i<n; i++) { 36 if (arr[i] != 0)sum++; 37 } 38 cout<<m<<" "<<sum<<endl; 39 } 40 return 0; 41 }
HihoCoder - 1631-Cats and Fish
标签:else 剪枝 coder esc iostream hoc mem ace als
原文地址:https://www.cnblogs.com/evidd/p/9004960.html