Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("rucsac.in");
- ofstream fout("rucsac.out");
- int n, g, v;
- vector< tuple<int,int,int> >ob; /// valoare, greutate
- double G, V;
- bool comp(tuple<int,int,int> a, tuple<int,int,int> b)
- {
- return (get<1>(a) * get<0>(b)) < (get<1>(b) * get<0>(a));
- }
- int main()
- {
- fin >> n >> G;
- for(int i = 1; i <= n; i++)
- {
- fin >> g;
- ob.push_back(make_tuple(0,g,i));
- }
- for(int i = 0; i < n; i++)
- {
- fin >> v;
- get<0>(ob[i]) = v;
- }
- sort(ob.begin(), ob.end(), comp);
- int i = 0;
- fout << " \n";
- while(G > 0)
- {
- if(G - get<1>(ob[i]) > 0)
- {
- G -= get<1>(ob[i]);
- V += get<0>(ob[i]);
- fout << get<2>(ob[i]) << ' ';
- }
- else
- {
- double ceva = ((get<1>(ob[i]) - G) * get<0>(ob[i])) / get<1>(ob[i]);
- V += ceva;
- G -= G;
- fout << get<2>(ob[i]) << ' ';
- }
- i++;
- }
- fout.close();
- fout.open("rucsac.out", ios::out | ios::in);
- fout << setprecision(2) << fixed << V;
- }
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("statii.in");
- ofstream fout("statii.out");
- int n, i = 2, x, dist_crt, dist, cate = 1;
- int main()
- {
- fin >> n >> x;
- fout << " \n" << 1 << ' ' ;
- for(int l = 1; l <= n; l++)
- {
- fin >> dist;
- dist_crt += dist;
- if(dist_crt >= x)
- {
- fout << i << ' ';
- cate++;
- dist_crt = 0;
- }
- i++;
- }
- fout.close();
- fout.open("statii.out", ios::out | ios::in);
- fout << cate;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement