delete pics to save space
This commit is contained in:
168
history_source/ccf 基础篇/U6/6.5.1.cpp
Normal file
168
history_source/ccf 基础篇/U6/6.5.1.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
struct con
|
||||
{
|
||||
int a,b;
|
||||
};
|
||||
con *cont;int len;
|
||||
template<class T_fsort>
|
||||
void fsort(T_fsort *left,T_fsort *right,bool (*cmp)(T_fsort a,T_fsort b),T_fsort *k)
|
||||
{
|
||||
if(right-left<=1) return;
|
||||
unsigned int len=right-left;
|
||||
fsort(left,left+len/2,cmp,k);
|
||||
fsort(left+len/2,right,cmp,k+len/2);
|
||||
int i=0,j=len/2,n=0;
|
||||
while(i<len/2&&j<len)
|
||||
{
|
||||
if(cmp(left[i],left[j])) k[n++]=left[i++];
|
||||
else k[n++]=left[j++];
|
||||
}
|
||||
while(i<len/2) k[n++]=left[i++];
|
||||
while(j<len) k[n++]=left[j++];
|
||||
for(int i=0;i<len;i++) left[i]=k[i];
|
||||
}
|
||||
template<class Tb_fsort>
|
||||
void fsort(Tb_fsort *left,Tb_fsort *right,bool (*cmp)(Tb_fsort a,Tb_fsort b))
|
||||
{
|
||||
if(right-left<=1) return;
|
||||
unsigned int len=right-left;
|
||||
Tb_fsort k[len];
|
||||
fsort(left,right,cmp,k);
|
||||
}
|
||||
bool cmp(con a,con b)
|
||||
{
|
||||
if(a.a<b.a) return 1;
|
||||
if(a.a>b.a) return 0;
|
||||
return a.b<b.b;
|
||||
}
|
||||
con* road(int a)
|
||||
{
|
||||
con *left,*right,*mid;
|
||||
left=cont;
|
||||
right=cont+len;
|
||||
while(left<right)
|
||||
{
|
||||
mid=left+(right-left)/2;
|
||||
if(mid->a>a) right=mid;
|
||||
if(mid->a<a) left=mid;
|
||||
if(mid->a==a)
|
||||
{
|
||||
left=mid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(left->a!=a) return 0;
|
||||
while(left>=cont&&left->a==a) left--;
|
||||
left++;
|
||||
return left;
|
||||
}
|
||||
template<class T_queue>
|
||||
struct Node_queue
|
||||
{
|
||||
T_queue num;
|
||||
Node_queue *next;
|
||||
};
|
||||
template<class a_queue>
|
||||
struct queue
|
||||
{
|
||||
Node_queue<a_queue> *head,*tail;
|
||||
int SIZE_queue;
|
||||
void beginning()
|
||||
{
|
||||
head=tail=new Node_queue<a_queue>;
|
||||
tail->next=head;
|
||||
SIZE_queue=0;
|
||||
}
|
||||
bool push(a_queue s)
|
||||
{
|
||||
SIZE_queue++;
|
||||
tail->num=s;
|
||||
if(tail->next==head)
|
||||
{
|
||||
tail->next=new Node_queue<a_queue>;
|
||||
tail->next->next=head;
|
||||
tail=tail->next;
|
||||
return 1;
|
||||
}
|
||||
tail=tail->next;
|
||||
return 0;
|
||||
}
|
||||
bool pop()
|
||||
{
|
||||
if(head==tail) return 1;
|
||||
head=head->next;
|
||||
SIZE_queue--;
|
||||
return 0;
|
||||
}
|
||||
a_queue front()
|
||||
{
|
||||
return head->num;
|
||||
}
|
||||
int size()
|
||||
{
|
||||
return SIZE_queue;
|
||||
}
|
||||
};
|
||||
struct BFS
|
||||
{
|
||||
int num;
|
||||
int step;
|
||||
};
|
||||
int main()
|
||||
{
|
||||
int n,m,p;
|
||||
ios::sync_with_stdio(0);
|
||||
cin>>n>>m>>p;
|
||||
cont=new con[m*2+10];
|
||||
con* x;
|
||||
int u,v;
|
||||
for(int i=0;i<m;i++)
|
||||
{
|
||||
cin>>u>>v;
|
||||
cont[len].a=u;
|
||||
cont[len].b=v;
|
||||
len++;
|
||||
cont[len].b=u;
|
||||
cont[len].a=v;
|
||||
len++;
|
||||
}
|
||||
fsort(cont,cont+len,cmp);
|
||||
bool guo[n+1]={0,1};
|
||||
queue<BFS>bfs;
|
||||
bfs.beginning();
|
||||
BFS r;
|
||||
r.num=1;
|
||||
r.step=0;
|
||||
bfs.push(r);
|
||||
while(bfs.size()>0&&bfs.front().step<=p)
|
||||
{
|
||||
x=road(bfs.front().num);
|
||||
if(x!=0)
|
||||
{
|
||||
while(x->a==bfs.front().num)
|
||||
{
|
||||
if(!guo[x->b])
|
||||
{
|
||||
r.num=x->b;
|
||||
r.step=bfs.front().step+1;
|
||||
bfs.push(r);
|
||||
guo[x->b]=1;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
bfs.pop();
|
||||
}
|
||||
int ans=0;
|
||||
for(int i=0;i<n+1;i++) ans+=guo[i];
|
||||
cout<<ans<<endl;
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
4 4 2
|
||||
1 2
|
||||
1 3
|
||||
2 3
|
||||
3 4
|
||||
*/
|
90
history_source/ccf 基础篇/U6/6.5.2.cpp
Normal file
90
history_source/ccf 基础篇/U6/6.5.2.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include<iostream>
|
||||
#include<cstring>
|
||||
using namespace std;
|
||||
template<class T_queue>
|
||||
struct Node_queue
|
||||
{
|
||||
T_queue num;
|
||||
Node_queue *next;
|
||||
};
|
||||
template<class a_queue>
|
||||
struct queue
|
||||
{
|
||||
Node_queue<a_queue> *head,*tail;
|
||||
int SIZE_queue;
|
||||
void beginning()
|
||||
{
|
||||
head=tail=new Node_queue<a_queue>;
|
||||
tail->next=head;
|
||||
SIZE_queue=0;
|
||||
}
|
||||
bool push(a_queue s)
|
||||
{
|
||||
SIZE_queue++;
|
||||
tail->num=s;
|
||||
if(tail->next==head)
|
||||
{
|
||||
tail->next=new Node_queue<a_queue>;
|
||||
tail->next->next=head;
|
||||
tail=tail->next;
|
||||
return 1;
|
||||
}
|
||||
tail=tail->next;
|
||||
return 0;
|
||||
}
|
||||
bool pop()
|
||||
{
|
||||
if(head==tail) return 1;
|
||||
head=head->next;
|
||||
SIZE_queue--;
|
||||
return 0;
|
||||
}
|
||||
a_queue front()
|
||||
{
|
||||
return head->num;
|
||||
}
|
||||
int size()
|
||||
{
|
||||
return SIZE_queue;
|
||||
}
|
||||
};
|
||||
int main()
|
||||
{
|
||||
int n,q,x,y,b;
|
||||
ios::sync_with_stdio(0);
|
||||
queue<int>ans;
|
||||
ans.beginning();
|
||||
cin>>n>>q;
|
||||
int train[n+1],front[n+1];
|
||||
memset(train,-1,n+1);
|
||||
memset(front,-1,n+1);
|
||||
for(int i=1;i<=n;i++)
|
||||
{
|
||||
cin>>x;
|
||||
train[i]=x;
|
||||
front[x]=i;
|
||||
}
|
||||
for(int i=0;i<q;i++)
|
||||
{
|
||||
cin>>b;
|
||||
if(b==0)
|
||||
{
|
||||
cin>>x;
|
||||
train[front[x]]=train[x];
|
||||
train[x]=-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cin>>x>>y;
|
||||
int n=x;
|
||||
for(int i=0;i<y;i++) n=train[n];
|
||||
ans.push(n==0?-1:n);
|
||||
}
|
||||
}
|
||||
while(ans.size()>0)
|
||||
{
|
||||
cout<<ans.front()<<endl;
|
||||
ans.pop();
|
||||
}
|
||||
return 0;
|
||||
}
|
70
history_source/ccf 基础篇/U6/6.5.3.cpp
Normal file
70
history_source/ccf 基础篇/U6/6.5.3.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include<string>
|
||||
#include<sstream>
|
||||
using namespace std;
|
||||
long double str_num(string sr)
|
||||
{
|
||||
stringstream li;
|
||||
li<<sr;
|
||||
long double ans;
|
||||
li>>ans;
|
||||
return ans;
|
||||
}
|
||||
string num_str(long double sr)
|
||||
{
|
||||
stringstream li;
|
||||
li<<sr;
|
||||
string ans;
|
||||
li>>ans;
|
||||
return ans;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
vector <string> sr;
|
||||
char li;
|
||||
while(true)
|
||||
{
|
||||
sr.resize(1);
|
||||
sr[0]="";
|
||||
while((li=getchar())!='\n')
|
||||
{
|
||||
if(li!=' ') sr[sr.size()-1]+=li;
|
||||
else
|
||||
{
|
||||
sr.push_back("");
|
||||
}
|
||||
}
|
||||
for(int i=sr.size()-1;i>=0;i--)
|
||||
{
|
||||
if(sr[i]=="+"||sr[i]=="-"||sr[i]=="*"||sr[i]=="/")
|
||||
{
|
||||
if(sr[i]=="+")
|
||||
{
|
||||
sr[i]=num_str(str_num(sr[i+1])+str_num(sr[i+2]));
|
||||
sr.erase(sr.begin()+i+1);
|
||||
sr.erase(sr.begin()+i+1);
|
||||
}
|
||||
if(sr[i]=="-")
|
||||
{
|
||||
sr[i]=num_str(str_num(sr[i+1])-str_num(sr[i+2]));
|
||||
sr.erase(sr.begin()+i+1);
|
||||
sr.erase(sr.begin()+i+1);
|
||||
}
|
||||
if(sr[i]=="*")
|
||||
{
|
||||
sr[i]=num_str(str_num(sr[i+1])*str_num(sr[i+2]));
|
||||
sr.erase(sr.begin()+i+1);
|
||||
sr.erase(sr.begin()+i+1);
|
||||
}
|
||||
if(sr[i]=="/")
|
||||
{
|
||||
sr[i]=num_str(str_num(sr[i+1])/str_num(sr[i+2]));
|
||||
sr.erase(sr.begin()+i+1);
|
||||
sr.erase(sr.begin()+i+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
cout<<sr[0];
|
||||
}
|
||||
}
|
48
history_source/ccf 基础篇/U6/6.5.5.cpp
Normal file
48
history_source/ccf 基础篇/U6/6.5.5.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
using namespace std;
|
||||
bool cmp(int a,int b)
|
||||
{
|
||||
return a<=b;
|
||||
}
|
||||
int *find(int *left,int *right,int n)
|
||||
{
|
||||
int *mid,*p;
|
||||
p=left;
|
||||
bool f=1;
|
||||
while(left<right)
|
||||
{
|
||||
mid=left+(right-left)/2;
|
||||
if(*mid==n)
|
||||
{
|
||||
f=0;
|
||||
left=mid;
|
||||
break;
|
||||
}
|
||||
if(*mid<n) left=mid;
|
||||
else right=mid;
|
||||
}
|
||||
if(f) return 0;
|
||||
if(*left!=n) return 0;
|
||||
while(*left==n&&left>=p) left--;
|
||||
left++;
|
||||
return left;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n,c;
|
||||
int ans=0;
|
||||
scanf("%d%d",&n,&c);
|
||||
int num[n];
|
||||
for(int i=0;i<n;i++) scanf("%d",num+i);
|
||||
sort(num,num+n,cmp);
|
||||
int x,*p;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
x=num[i]-c;
|
||||
p=find(num,num+n,x);
|
||||
if(p!=0) while(*p==x&&p<num+n) ans++,p++;
|
||||
}
|
||||
printf("%d\n",ans);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user