#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <cstdlib> #include <stack> #include <vector> #include <functional> #include <bits/stdc++.h> #include <sstream> #include <iomanip> #include <cmath> #include <cctype> #include <bitset> using namespace std; vector < long long > boki; vector < pair<long long,long long> > prostokaty; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long h, w, tym; long long obraz, ile_obr, ile_pop; int ile, kon; cin >> h >> w; cin >>ile; tym=w; //cout << h << " " << w << endl; for (int n=1; n<=ile; n++) { cin >> obraz; boki.push_back(obraz); } //for (int n=0; n<ile; n++) // cout << boki[n] << " "; //cout << endl; ile_obr=0; //cout << h%boki[0] << " " << w%boki[0] << endl; //if (((ile==1) && (boki[0]!=1)) || (((h%boki[0]!=0) || (w%boki[0]!=0)) && (boki[0]!=1))) if ((h%boki[0]!=0) || (w%boki[0]!=0)) cout << -1; else { for (int n=ile-1; n>=0; n--) { if ((h/boki[n]>=1) && (w/boki[n]>=1)) { //cout << boki[n] << " " << h << " y " << w << " " << (h/boki[n]) << " " << (w/boki[n]) << " " << ile_obr << endl; ile_pop=(h/boki[n]); ile_obr=ile_obr+((h/boki[n])*(w/boki[n])); h=h-(boki[n]*(h/boki[n])); w=w-(boki[n]*(w/boki[n])); //cout << boki[n] << " " << h << " z " << w << " " << (h/boki[n]) << " " << (w/boki[n]) << " " << ile_obr << endl; for (int k=n-1; k>=0 ; k--) { if (w/boki[k]>=1) { //cout << h << " w " << w << " " << ile_pop*boki[n]/boki[k] << " " << boki[n]/boki[k] << " " << (w/boki[k])<< " " << ile_obr << endl; ile_obr=ile_obr+ile_pop*(boki[n]/boki[k])*(w/boki[k]); w=w-(boki[k]*(w/boki[k])); //cout << h << " x " << w << " " << ile_pop*boki[n]/boki[k] << " " << boki[n]/boki[k] << " " << (w/boki[k])<< " " << ile_obr << endl; } } w=tym; } if (w==0) { kon=n; break; } } //cout << boki[kon] << " " << h << " " << w << " " << 50-ile_obr<< endl; while (kon>=0) { ile_obr=ile_obr+((h/boki[kon])*(tym/boki[kon])); h=h-(boki[kon]*(h/boki[kon])); //cout << boki[kon] << " " << h << " " << w << " " << 50-ile_obr<< endl; kon=kon-1; } if (ile_obr!=0) cout << ile_obr; else cout << -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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <cstdlib> #include <stack> #include <vector> #include <functional> #include <bits/stdc++.h> #include <sstream> #include <iomanip> #include <cmath> #include <cctype> #include <bitset> using namespace std; vector < long long > boki; vector < pair<long long,long long> > prostokaty; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long h, w, tym; long long obraz, ile_obr, ile_pop; int ile, kon; cin >> h >> w; cin >>ile; tym=w; //cout << h << " " << w << endl; for (int n=1; n<=ile; n++) { cin >> obraz; boki.push_back(obraz); } //for (int n=0; n<ile; n++) // cout << boki[n] << " "; //cout << endl; ile_obr=0; //cout << h%boki[0] << " " << w%boki[0] << endl; //if (((ile==1) && (boki[0]!=1)) || (((h%boki[0]!=0) || (w%boki[0]!=0)) && (boki[0]!=1))) if ((h%boki[0]!=0) || (w%boki[0]!=0)) cout << -1; else { for (int n=ile-1; n>=0; n--) { if ((h/boki[n]>=1) && (w/boki[n]>=1)) { //cout << boki[n] << " " << h << " y " << w << " " << (h/boki[n]) << " " << (w/boki[n]) << " " << ile_obr << endl; ile_pop=(h/boki[n]); ile_obr=ile_obr+((h/boki[n])*(w/boki[n])); h=h-(boki[n]*(h/boki[n])); w=w-(boki[n]*(w/boki[n])); //cout << boki[n] << " " << h << " z " << w << " " << (h/boki[n]) << " " << (w/boki[n]) << " " << ile_obr << endl; for (int k=n-1; k>=0 ; k--) { if (w/boki[k]>=1) { //cout << h << " w " << w << " " << ile_pop*boki[n]/boki[k] << " " << boki[n]/boki[k] << " " << (w/boki[k])<< " " << ile_obr << endl; ile_obr=ile_obr+ile_pop*(boki[n]/boki[k])*(w/boki[k]); w=w-(boki[k]*(w/boki[k])); //cout << h << " x " << w << " " << ile_pop*boki[n]/boki[k] << " " << boki[n]/boki[k] << " " << (w/boki[k])<< " " << ile_obr << endl; } } w=tym; } if (w==0) { kon=n; break; } } //cout << boki[kon] << " " << h << " " << w << " " << 50-ile_obr<< endl; while (kon>=0) { ile_obr=ile_obr+((h/boki[kon])*(tym/boki[kon])); h=h-(boki[kon]*(h/boki[kon])); //cout << boki[kon] << " " << h << " " << w << " " << 50-ile_obr<< endl; kon=kon-1; } if (ile_obr!=0) cout << ile_obr; else cout << -1; } return 0; } |