Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //solution by Wsl_F
- #include <bits/stdc++.h>
- #include "majority.h"
- #include <message.h>
- using namespace std;
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- typedef long long LL;
- typedef unsigned long long uLL;
- typedef double dbl;
- typedef vector<int> vi;
- typedef vector<LL> vL;
- typedef vector<string> vs;
- typedef pair<int,int> pii;
- typedef pair<LL,LL> pLL;
- #define mp(x,y) make_pair((x),(y))
- #define pb(x) push_back(x)
- #define sqr(x) ((x)*(x))
- int main()
- {
- int nodesNum= NumberOfNodes();
- int myNode= MyNodeId();
- int n= GetN();
- map<int, int> mp;
- for (int i= myNode; i<n; i+= nodesNum)
- mp[GetVote(i)]++;
- if (myNode)
- {
- vector<pii> v;
- for (auto& kv : mp)
- v.pb(kv);
- int sz= v.size();
- PutInt(0, sz);
- for (pii& kv : v)
- {
- PutInt(0, kv.first);
- PutInt(0, kv.second);
- }
- Send(0);
- }
- else
- {
- for (int node= 1; node < nodesNum; node++)
- {
- Receive(node);
- int m= GetInt(node);
- for (int i= 0; i<m; i++)
- {
- int k= GetInt(node);
- int v= GetInt(node);
- mp[k]+= v;
- }
- }
- int n2= n/2;
- for (auto& kv : mp)
- if (kv.second > n2)
- {
- cout<<kv.first<<endl;
- return 0;
- }
- cout<<"NO WINNER"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement