标签:print ios sync pat ns2 define false soft str
1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 typedef struct{ 5 int add,data,nex; 6 }Node; 7 Node node[100007],ans[100007],ans2[100007]; 8 map<int,int>mp; 9 int main(){ 10 //ios::sync_with_stdio(false); 11 //cin.tie(NULL); 12 //cout.tie(NULL); 13 int s,n,k; 14 scanf("%d%d%d",&s,&n,&k); 15 for(int i=1;i<=n;++i){ 16 scanf("%d%d%d",&node[i].add,&node[i].data,&node[i].nex); 17 mp[node[i].add]=i; 18 } 19 int cnt=0; 20 while(s!=-1){ 21 int num=mp[s]; 22 ans[++cnt].add=node[num].add; 23 ans[cnt].data=node[num].data; 24 ans[cnt].nex=node[num].nex; 25 s=ans[cnt].nex; 26 } 27 int cnt2=0; 28 int x=cnt/k; 29 if(cnt%k) 30 ++x; 31 for(int i=x;i;--i){ 32 for(int j=(i-1)*k+1;j<=min(cnt,i*k);++j){ 33 ans2[++cnt2].add=ans[j].add; 34 ans2[cnt2].data=ans[j].data; 35 ans2[cnt2].nex=ans[j].nex; 36 } 37 if(i==1) 38 ans2[cnt2].nex=-1; 39 else 40 ans2[cnt2].nex=ans[(i-2)*k+1].add; 41 } 42 for(int i=1;i<=cnt2;++i){ 43 if(i<cnt2) 44 printf("%05d %d %05d\n",ans2[i].add,ans2[i].data,ans2[i].nex); 45 else 46 printf("%05d %d -1",ans2[i].add,ans2[i].data); 47 } 48 return 0; 49 }
标签:print ios sync pat ns2 define false soft str
原文地址:https://www.cnblogs.com/ldudxy/p/12255723.html