#include <iostream> #include <vector> #include <stdlib.h> #include <math.h> using namespace std; int h,w,n,v,tempe; bool intret; int main() { cin >> h >> w >> n; int d[n]; int wy[n]; int sz[n]; for(int i = 0 ; i < n; i++) { cin >> d[i]; if(i == 0 && (w%d[i] != 0 || h%d[i] != 0)) { intret = true; } } if(intret) { cout << -1; return 0; } int o,th =0; th = h; for(int k = n; k > 0;k--) { o = 0; while(true) { if(th-d[k-1] < 0) { break; } th -= d[k-1]; o++; } wy[k-1] = o; } th = w; for(int k = n; k > 0;k--) { o = 0; while(true) { if(th-d[k-1] < 0) { break; } th -= d[k-1]; o++; } sz[k-1] = o; } for(int i = n-1;i >= 0; i--) { if( wy[i]==0) { continue; } if(w%wy[i] == 0) { v += w/wy[i]; continue; } for(int j = 0; j < i;j++) { v += wy[i]*(d[i]/d[i-1])*d[n-i]; } } cout << v -1; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <iostream> #include <vector> #include <stdlib.h> #include <math.h> using namespace std; int h,w,n,v,tempe; bool intret; int main() { cin >> h >> w >> n; int d[n]; int wy[n]; int sz[n]; for(int i = 0 ; i < n; i++) { cin >> d[i]; if(i == 0 && (w%d[i] != 0 || h%d[i] != 0)) { intret = true; } } if(intret) { cout << -1; return 0; } int o,th =0; th = h; for(int k = n; k > 0;k--) { o = 0; while(true) { if(th-d[k-1] < 0) { break; } th -= d[k-1]; o++; } wy[k-1] = o; } th = w; for(int k = n; k > 0;k--) { o = 0; while(true) { if(th-d[k-1] < 0) { break; } th -= d[k-1]; o++; } sz[k-1] = o; } for(int i = n-1;i >= 0; i--) { if( wy[i]==0) { continue; } if(w%wy[i] == 0) { v += w/wy[i]; continue; } for(int j = 0; j < i;j++) { v += wy[i]*(d[i]/d[i-1])*d[n-i]; } } cout << v -1; return 0; } |