I'm not able to find the error in this code below sometimes it showing floating-point exception and sometimes it prints the output showing time limit exceed.
#include<bits/stdc++.h>
using namespace std;
int main(){long int t,i,j,n,k,start,d,z;
long int pos;
cin>>t;
for(i=0;i<t;i++){
cin>>n>>k;
vector<int>myset(n+1);
vector<int>::iterator it;
for(j=0;j<n;j++) {
z=j+1;
myset.push_back(z);
}
it=myset.begin();
pos=0;
int m=n;
start=2;
while(k>0){
start=(start+2);
if(start>m){
start=start%m;
}
k=k-1;
}
it=myset.begin();
pos=start-1;
it=it+pos;
myset.erase(it);
d=start;
while(!myset.empty()){
it=myset.begin();
pos=((pos+2)%m);
start=myset[pos];
it=it+pos;
myset.erase(it);
m=m-1;
pos=pos-1;
d=start;
}
cout<<d<<"\n" ;
}
}
What is the error in this code?
I'm not able to find the actual error in this code but most probably I think the error in this vector declaration but not sure help me to find out the error in this code?
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Aucun commentaire:
Enregistrer un commentaire