#include <cstdio>
#include <cstdlib>
#include <math.h>
#include "message.h"
#include "poszukiwania.h"
using namespace std;
/*
long long SignalLength(){return 5;}
long long SeqLength(){return 11;}
long long SignalAt(long long i){int t[6]={0,1,2,3,2,1}; return t[i];}
long long SeqAt(long long i){int t[12]={0,2,1,2,3,2,1,2,3,2,1,2}; return t[i];}
int NumberOfNodes(){return 8;}
int MyNodeId(){return 7;}
void Send(int a){}
void PutInt(int a, int b){printf("%d-%d\n",a,b);}
int Receive(int a){return -1;};
int GetInt(int a){return 0;}
*/
int main()
{
long long istart,istop;
int a,b,cnt,tabcnt[200],sukces, nodesize, siglen, inst, instcnt;
siglen=SignalLength();
nodesize=(int)ceil((SeqLength()-siglen+1.0)/NumberOfNodes());
istart=1+nodesize*MyNodeId();
istop=istart+nodesize-1;
if (istop>(SeqLength()-siglen+1)) istop=SeqLength()-siglen+1;
if (istop<istart) {
PutInt(0,0);
Send(0);
return 0;
}
cnt=0;
for (a=istart; a<=istop; a++)
{
sukces=1;
for (b=1; b<=siglen; b++)
if (SignalAt(b)!=SeqAt(a+b-1))
{
sukces=0;
break;
}
if ((sukces)) cnt++;
}
if (MyNodeId()==0){
instcnt=NumberOfNodes()-1;
while (instcnt>0){
inst=Receive(-1);
cnt+=GetInt(inst);
instcnt--;
}
printf("%d\n",cnt);
} else {
PutInt(0,cnt);
Send(0);
}
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 | #include <cstdio> #include <cstdlib> #include <math.h> #include "message.h" #include "poszukiwania.h" using namespace std; /* long long SignalLength(){return 5;} long long SeqLength(){return 11;} long long SignalAt(long long i){int t[6]={0,1,2,3,2,1}; return t[i];} long long SeqAt(long long i){int t[12]={0,2,1,2,3,2,1,2,3,2,1,2}; return t[i];} int NumberOfNodes(){return 8;} int MyNodeId(){return 7;} void Send(int a){} void PutInt(int a, int b){printf("%d-%d\n",a,b);} int Receive(int a){return -1;}; int GetInt(int a){return 0;} */ int main() { long long istart,istop; int a,b,cnt,tabcnt[200],sukces, nodesize, siglen, inst, instcnt; siglen=SignalLength(); nodesize=(int)ceil((SeqLength()-siglen+1.0)/NumberOfNodes()); istart=1+nodesize*MyNodeId(); istop=istart+nodesize-1; if (istop>(SeqLength()-siglen+1)) istop=SeqLength()-siglen+1; if (istop<istart) { PutInt(0,0); Send(0); return 0; } cnt=0; for (a=istart; a<=istop; a++) { sukces=1; for (b=1; b<=siglen; b++) if (SignalAt(b)!=SeqAt(a+b-1)) { sukces=0; break; } if ((sukces)) cnt++; } if (MyNodeId()==0){ instcnt=NumberOfNodes()-1; while (instcnt>0){ inst=Receive(-1); cnt+=GetInt(inst); instcnt--; } printf("%d\n",cnt); } else { PutInt(0,cnt); Send(0); } return 0; } |
English