count = j->count % people.size(); if (count == 0) { count = people.size(); }
struct Person{ Person(int i, int c) { id = i; count = c; } int id; int count; };
#include <list> list <Person> people; typedef list::iterator peopIt;
void Fix(peopIt & j) { if (j == people.end()) { j = people.begin(); } }
#include <iostream> #include <algorithm> #include <vector> using namespace std; class Judge{ public: Judge(int i, long double d) { id = i; distance = d; } bool operator <(const Judge & other) { return distance > other.distance; } void Tell() { cout << id << " " << distance; } private: int id; long double distance; }; int main() { vector<Judge> people; srand(time(nullptr)); for (int i=0;i<10;i++) { people.push_back(Judge(i,rand()%20)); } make_heap(people.begin(), people.end()); while (people.size() > 0) { people.front().Tell(); cout << endl; pop_heap(people.begin(), people.end()); people.pop_back(); } }
struct Judge { Judge(int xc, int yc) { x = xc; y = yc; } int x, y; };
int main() { int judges, tars, feathers; long double totalDistance = 0; vector <Judge> judgeList; cin >> judges >> tars >> feathers; for (int i=0;i> x >>y; judgeList.push_back(Judge(x,y)); } totalDistance = ProcessItem(judgeList, tars); totalDistance += ProcessItem(judgeList, feathers); cout << fixed << setprecision(6); cout << totalDistance << endl; return 0; }
struct Place{ Place(int j, int i, long double d) { id = i; judge = j; distance = d; } long double distance; int judge; int id; bool operator < (const Place & other) { if (distance == other.distance) { if (judge == other.judge) { return id > other.id; } else { return judge > other.judge; } } else { return distance > other.distance; } } };
long double ProcessItem( vector& judgeList, int count) { int i; vector <Place> pits; int judgesFound = 0; long double totalDistance = 0;
vector<bool> pitUsed(count, false); vector<bool> judgeUsed(judgeList.size(),false);
for(int i=0;<count; i++) { int x,y; long double distance; cin >> x >> y; for (int j=0; j<judgeList.size();j++) { distance = Distance(judgeList[j].x, judgeList[j].y, x,y); pits.push_back(Place(j,i,distance)); } }
make_heap(pits.begin(), pits.end());
while (pits.size() > 0 and judgesFound < judgeList.size()) { int j = pits.front().judge; int p = pits.front().id; if (!judgeUsed[j] and !pitUsed[p]) { totalDistance += pits.front().distance; judgeUsed[j] = true; pitUsed[p] = true; judgesFound ++; } pop_heap(pits.begin(), pits.end()); pits.pop_back(); }
n = 1000000 m = 1377387113 a = 1377387114 c = 169365001 x0 = 123456
cin >> n >> m >> a >> c >> x0; vectorseq; long xOld = x0; long xNew; for(int i=0;i<n;i++) { xNew = ((xOld * a) %m + c) % m; seq.push_back(xNew); xOld = xNew; }
int count = 0; for(auto x: seq) { if (Bsearch(x,seq,0, seq.size()-1)) { count ++; } }