#include<cstdio> #include<algorithm> //#include<iostream> #include "message.h" #include "poszukiwania.h" using namespace std; const long long int NMAX = (1000*1000*1000+7)*2; int main(){ long long int S = SignalLength(); long long int M = SeqLength(); int NON = NumberOfNodes(); int MNI = MyNodeId(); //if(MNI == 0) cout << "NON = " << NON << " MNI = " << MNI << endl; long long int start = (M/NON)*MNI; long long int koniec = (M/NON)*(MNI+1)-1; // long long int start = 0; // long long int koniec = M-1; // if(MNI == 0) cout << "start=" << start << " koniec=" << koniec << endl; if(MNI+1 == NON) koniec = M-1; long long int wynik = 0; for(long long int q = start; q <= koniec && q + S <= M ; q++){ int akt = 1; for(long long int i = q; i < M && i < q + S; i++){ // if(MNI == 0) cout << "q=" << q << " i=" << i << endl; if(SignalAt(i-q+1) != SeqAt(i+1)){ akt = 0; break; } } wynik += akt; } PutLL(0,wynik); Send(0); if(MNI == 0){ long long int suma = 0; for(int i = 0; i < NON; i++){ //printf("i = %d",i); int instancja = Receive(-1); int v = GetLL(instancja); suma += v; } printf("%lld\n",suma); // printf("%lld\n", wynik); } 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 | #include<cstdio> #include<algorithm> //#include<iostream> #include "message.h" #include "poszukiwania.h" using namespace std; const long long int NMAX = (1000*1000*1000+7)*2; int main(){ long long int S = SignalLength(); long long int M = SeqLength(); int NON = NumberOfNodes(); int MNI = MyNodeId(); //if(MNI == 0) cout << "NON = " << NON << " MNI = " << MNI << endl; long long int start = (M/NON)*MNI; long long int koniec = (M/NON)*(MNI+1)-1; // long long int start = 0; // long long int koniec = M-1; // if(MNI == 0) cout << "start=" << start << " koniec=" << koniec << endl; if(MNI+1 == NON) koniec = M-1; long long int wynik = 0; for(long long int q = start; q <= koniec && q + S <= M ; q++){ int akt = 1; for(long long int i = q; i < M && i < q + S; i++){ // if(MNI == 0) cout << "q=" << q << " i=" << i << endl; if(SignalAt(i-q+1) != SeqAt(i+1)){ akt = 0; break; } } wynik += akt; } PutLL(0,wynik); Send(0); if(MNI == 0){ long long int suma = 0; for(int i = 0; i < NON; i++){ //printf("i = %d",i); int instancja = Receive(-1); int v = GetLL(instancja); suma += v; } printf("%lld\n",suma); // printf("%lld\n", wynik); } return 0; } |