delete pics to save space
This commit is contained in:
13
history_source/ccf 基础篇/U1/1.6.1.cpp
Normal file
13
history_source/ccf 基础篇/U1/1.6.1.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
char sr;
|
||||
int add;
|
||||
while(true)
|
||||
{
|
||||
add=0;
|
||||
while((sr=getchar())!='\n') add+=sr-'0';
|
||||
cout<<add<<endl;
|
||||
}
|
||||
}
|
21
history_source/ccf 基础篇/U1/1.6.2.cpp
Normal file
21
history_source/ccf 基础篇/U1/1.6.2.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
using namespace std;
|
||||
long long zk(int sr)
|
||||
{
|
||||
if(sr==2) return 2;
|
||||
if(sr==1) return 1;
|
||||
return zk(sr-1)*2+zk(sr-2);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
vector <int> sr;
|
||||
int n;
|
||||
while(true)
|
||||
{
|
||||
cin>>n;
|
||||
sr.resize(n);
|
||||
for(int i=0;i<n;i++) cin>>sr[i];
|
||||
for(int i=0;i<n;i++) cout<<zk(sr[i])<<endl;
|
||||
}
|
||||
}
|
40
history_source/ccf 基础篇/U1/1.6.3.cpp
Normal file
40
history_source/ccf 基础篇/U1/1.6.3.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
long double f_j(int sr)
|
||||
{
|
||||
if(sr<0) return 0;
|
||||
if(sr==0) return 1;
|
||||
return sr*f_j(sr-1);
|
||||
}
|
||||
long double C(int x,int y)
|
||||
{
|
||||
return f_j(x)/f_j(x-y)/f_j(y);
|
||||
}
|
||||
long double big_(long double a,long double b)
|
||||
{
|
||||
return (a>b)?a:b;
|
||||
}
|
||||
long double small_(long double a,long double b)
|
||||
{
|
||||
return (a<b)?a:b;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n,add;
|
||||
while(true)
|
||||
{
|
||||
cin>>n;
|
||||
add=0;
|
||||
for(int one=0;one<=n;one++)
|
||||
{
|
||||
for(int two=0;two<=n/2;two++)
|
||||
{
|
||||
if(one+two*2==n)
|
||||
{
|
||||
add+=C(big_(one,two)+small_(one,two),small_(one,two));
|
||||
}
|
||||
}
|
||||
}
|
||||
cout<<add<<endl;
|
||||
}
|
||||
}
|
22
history_source/ccf 基础篇/U1/1.6.4.cpp
Normal file
22
history_source/ccf 基础篇/U1/1.6.4.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include<cstdio>
|
||||
using namespace std;
|
||||
int answer(int a,int b,int x)
|
||||
{
|
||||
if(b==1) return 1;
|
||||
int ans=0;
|
||||
for(int i=x;i*b<=a;i++) ans+=answer(a-i,b-1,i);
|
||||
return ans;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int t;
|
||||
scanf("%d",&t);
|
||||
int a,b,ans[t];
|
||||
for(int i=0;i<t;i++)
|
||||
{
|
||||
scanf("%d%d",&a,&b);
|
||||
ans[i]=answer(a,b,0);
|
||||
}
|
||||
for(int i=0;i<t;i++) printf("%d\n",ans[i]);
|
||||
return 0;
|
||||
}
|
35
history_source/ccf 基础篇/U1/1.6.5.cpp
Normal file
35
history_source/ccf 基础篇/U1/1.6.5.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include<iostream>
|
||||
#include<cmath>
|
||||
using namespace std;
|
||||
int log2(int y)
|
||||
{
|
||||
return log(y)/log(2);
|
||||
}
|
||||
void wrote(int sr)
|
||||
{
|
||||
bool f=0;
|
||||
for(int i=log2(sr);sr>0;i--)
|
||||
{
|
||||
if(sr>=pow(2,i))
|
||||
{
|
||||
if(f) cout<<"+";
|
||||
f=1;
|
||||
cout<<"2(";
|
||||
switch(i)
|
||||
{
|
||||
case 1:cout<<"2(0)";break;
|
||||
case 2:cout<<"2";break;
|
||||
default:wrote(i);
|
||||
}
|
||||
cout<<")";
|
||||
sr-=pow(2,i);
|
||||
}
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
wrote(n);
|
||||
return 0;
|
||||
}
|
18
history_source/ccf 基础篇/U2/2.4.1.cpp
Normal file
18
history_source/ccf 基础篇/U2/2.4.1.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
using namespace std;
|
||||
bool pan(string sr)
|
||||
{
|
||||
if(!((sr[0]>='a'&&sr[0]<='z')||(sr[0]>='A'&&sr[0]<='Z')||sr[0]=='_')) return 0;
|
||||
for(int i=0;i<sr.size();i++) if(!((sr[i]>='a'&&sr[i]<='z')||(sr[i]>='A'&&sr[i]<='Z')||sr[i]=='_'||(sr[i]>='0'&&sr[i]<='9'))) return 0;
|
||||
return 1;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
string sr;
|
||||
getline(cin,sr);
|
||||
if(pan(sr)) cout<<"yes";
|
||||
else cout<<"no";
|
||||
cout<<endl;
|
||||
return 0;
|
||||
}
|
24
history_source/ccf 基础篇/U2/2.4.2.cpp
Normal file
24
history_source/ccf 基础篇/U2/2.4.2.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int num[26],b;
|
||||
char sr;
|
||||
for(int i=0;i<26;i++) num[i]=0;
|
||||
while((sr=getchar())!='\n') if(sr>='A'&&sr<='Z') num[sr-'A']++;
|
||||
while((sr=getchar())!='\n') if(sr>='A'&&sr<='Z') num[sr-'A']++;
|
||||
while((sr=getchar())!='\n') if(sr>='A'&&sr<='Z') num[sr-'A']++;
|
||||
while((sr=getchar())!='\n') if(sr>='A'&&sr<='Z') num[sr-'A']++;
|
||||
b=num[0];
|
||||
for(int i=0;i<26;i++) if(num[i]>b) b=num[i];
|
||||
for(int i=b;i>=0;i--)
|
||||
{
|
||||
for(int j=0;j<26;j++)
|
||||
if(num[j]>i) cout<<"* ";
|
||||
else cout<<" ";
|
||||
cout<<endl;
|
||||
}
|
||||
for(int i=0;i<26;i++) cout<<char(i+'A')<<" ";
|
||||
cout<<endl;
|
||||
return 0;
|
||||
}
|
62
history_source/ccf 基础篇/U2/2.4.3.cpp
Normal file
62
history_source/ccf 基础篇/U2/2.4.3.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
#include<vector>
|
||||
using namespace std;
|
||||
void turn(string &sr)
|
||||
{
|
||||
char li;
|
||||
for(int i=0,j=sr.size()-1;i<j;i++,j--)
|
||||
{
|
||||
li=sr[i];
|
||||
sr[i]=sr[j];
|
||||
sr[j]=li;
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
string sr,li2;
|
||||
vector <char> li;
|
||||
int p1,p2,p3;
|
||||
cin>>p1>>p2>>p3;
|
||||
cin>>sr;
|
||||
for(int i=1;i<sr.size();i++)
|
||||
{
|
||||
if(sr[i]=='-')
|
||||
{
|
||||
if(sr[i+1]-sr[i-1]==1)
|
||||
{
|
||||
sr.erase(i,1);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
if(sr[i+1]<=sr[i-1]) continue;
|
||||
sr.erase(i,1);
|
||||
li.clear();
|
||||
for(int j=1;j+sr[i-1]<sr[i];j++)
|
||||
{
|
||||
for(int k=0;k<p2;k++)
|
||||
{
|
||||
switch(p1)
|
||||
{
|
||||
case 1:
|
||||
li.push_back(char(sr[i-1]+j));
|
||||
break;
|
||||
case 2:
|
||||
li.push_back(char(sr[i-1]+j-32));
|
||||
break;
|
||||
case 3:
|
||||
li.push_back('*');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
li2="";
|
||||
for(int i=0;i<li.size();i++) li2+=li[i];
|
||||
if(p3==2) turn(li2);
|
||||
sr.insert(i,li2);
|
||||
i+=li.size()-1;
|
||||
}
|
||||
}
|
||||
cout<<sr<<endl;
|
||||
return 0;
|
||||
}
|
62
history_source/ccf 基础篇/U2/2.4.4.cpp
Normal file
62
history_source/ccf 基础篇/U2/2.4.4.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
using namespace std;
|
||||
string sr1;
|
||||
short T1[52],T2[52];
|
||||
int hash_(char n)
|
||||
{
|
||||
if(n>='A'&&n<='Z') return n-'A';
|
||||
return n-'a'+26;
|
||||
}
|
||||
void insert(char a){T2[hash_(a)]++;}
|
||||
void delete_(char a)
|
||||
{
|
||||
T2[hash_(a)]--;
|
||||
if(T2[hash_(a)]<0) T2[hash_(a)]=0;
|
||||
}
|
||||
bool check()
|
||||
{
|
||||
for(int i=0;i<52;i++) if(T1[i]!=T2[i]) return 0;
|
||||
return 1;
|
||||
}
|
||||
struct Node
|
||||
{
|
||||
char c;
|
||||
Node *next;
|
||||
};
|
||||
int main()
|
||||
{
|
||||
freopen("in.txt","r",stdin);
|
||||
ios::sync_with_stdio(0);
|
||||
int ans=0;
|
||||
cin>>sr1;
|
||||
for(int i=0;i<sr1.size();i++)
|
||||
{
|
||||
if(sr1[i]>='A'&&sr1[i]<='Z') T1[sr1[i]-'A']++;
|
||||
else T1[sr1[i]-'a'+26]++;
|
||||
}
|
||||
char ch;
|
||||
Node *head,*last;
|
||||
last=head=new Node;
|
||||
for(int i=0;i<sr1.size();i++)
|
||||
{
|
||||
ch=getchar();
|
||||
insert(ch);
|
||||
last->c=ch;
|
||||
last->next=new Node;
|
||||
last=last->next;
|
||||
}
|
||||
last->next=head;
|
||||
if(check()) ans++;
|
||||
while(ch=getchar(),ch!='\n')
|
||||
{
|
||||
delete_(head->c);
|
||||
head=head->next;
|
||||
last->c=ch;
|
||||
last=last->next;
|
||||
insert(ch);
|
||||
if(check()) ans++;
|
||||
}
|
||||
cout<<ans<<endl;
|
||||
return 0;
|
||||
}
|
40
history_source/ccf 基础篇/U2/2.4.5.cpp
Normal file
40
history_source/ccf 基础篇/U2/2.4.5.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
#include<vector>
|
||||
using namespace std;
|
||||
void turn(string &sr)
|
||||
{
|
||||
for(int i=0;i<sr.size();i++) if(sr[i]>='A'&&sr[i]<='Z') sr[i]+=32;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
string find,li;
|
||||
vector <string> sr;
|
||||
char sr2;
|
||||
int add,i;
|
||||
cin>>find;
|
||||
sr2=getchar();
|
||||
sr.clear();
|
||||
li="";
|
||||
while((sr2=getchar())!='\n')
|
||||
{
|
||||
if(sr2!=' ') li+=sr2;
|
||||
else
|
||||
{
|
||||
sr.push_back(li);
|
||||
li="";
|
||||
}
|
||||
}
|
||||
turn(find);
|
||||
for(int i=0;i<sr.size();i++) turn(sr[i]);
|
||||
add=0;
|
||||
for(int i=0;i<sr.size();i++) if(sr[i]==find) add++;
|
||||
if(add!=0)
|
||||
{
|
||||
cout<<add<<" ";
|
||||
for(i=0;i<sr.size();i++) if(find==sr[i]) break;
|
||||
cout<<i<<endl;
|
||||
}
|
||||
else cout<<-1<<endl;
|
||||
return 0;
|
||||
}
|
48
history_source/ccf 基础篇/U2/2.4.6.cpp
Normal file
48
history_source/ccf 基础篇/U2/2.4.6.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
using namespace std;
|
||||
struct Node
|
||||
{
|
||||
int num;
|
||||
Node *next;
|
||||
};
|
||||
string a,b;
|
||||
int maxn(int i,int j)
|
||||
{
|
||||
int ans=0;
|
||||
for(;i<a.size()&&j<b.size()&&a[i]==b[j];i++,j++) ans++;
|
||||
return ans;
|
||||
}
|
||||
int answer()
|
||||
{
|
||||
a=a+a.substr(0,a.size()-1);
|
||||
b=b+b.substr(0,b.size()-1);
|
||||
int ans=-1;
|
||||
for(int i=0;i<a.size();i++)
|
||||
for(int j=0;j<b.size();j++)
|
||||
ans=max(ans,maxn(i,j));
|
||||
return ans;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
// freopen("in.txt","r",stdin);
|
||||
ios::sync_with_stdio(0);
|
||||
Node *head,*last,*p;
|
||||
head=last=new Node;
|
||||
while(true)
|
||||
{
|
||||
cin>>a>>b;
|
||||
if(a.size()==1||b.size()==1) break;
|
||||
last->num=answer();
|
||||
last->next=new Node;
|
||||
last=last->next;
|
||||
}
|
||||
p=head;
|
||||
while(p!=last)
|
||||
{
|
||||
cout<<p->num<<endl;
|
||||
p=p->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
38
history_source/ccf 基础篇/U3/3.5.1.cpp
Normal file
38
history_source/ccf 基础篇/U3/3.5.1.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
using namespace std;
|
||||
struct people
|
||||
{
|
||||
string name;
|
||||
int f;
|
||||
};
|
||||
int n;
|
||||
int main()
|
||||
{
|
||||
people sr[100];
|
||||
int k;
|
||||
while(true)
|
||||
{
|
||||
cin>>n>>k;
|
||||
for(int i=0;i<n;i++) cin>>sr[i].name>>sr[i].f;
|
||||
bool b;
|
||||
people x;
|
||||
for(int i=n-1;i>0;i--)
|
||||
{
|
||||
b=1;
|
||||
for(int j=0;j<i;j++)
|
||||
{
|
||||
if(sr[j].f>sr[j+1].f){
|
||||
x=sr[j];
|
||||
sr[j]=sr[j+1];
|
||||
sr[j+1]=x;
|
||||
b=0;
|
||||
}
|
||||
}
|
||||
if(b) break;
|
||||
}
|
||||
cout<<endl;
|
||||
cout<<sr[k-1].name<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
63
history_source/ccf 基础篇/U3/3.5.2.cpp
Normal file
63
history_source/ccf 基础篇/U3/3.5.2.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
using namespace std;
|
||||
struct Sr
|
||||
{
|
||||
int num;
|
||||
int p=0;
|
||||
};
|
||||
int main()
|
||||
{
|
||||
vector <int> sr1;
|
||||
vector <Sr> sr2;
|
||||
Sr li;
|
||||
int n;
|
||||
while(true)
|
||||
{
|
||||
cin>>n;
|
||||
sr1.resize(n);
|
||||
for(int i=0;i<n;i++) cin>>sr1[i];
|
||||
sr2.clear();
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
li.num=sr1[i];
|
||||
sr2.push_back(li);
|
||||
}
|
||||
bool b;
|
||||
for(int i=sr2.size()-1;i>0;i--)
|
||||
{
|
||||
b=1;
|
||||
for(int j=0;j<i;j++)
|
||||
{
|
||||
if(sr2[j].num>sr2[j+1].num){
|
||||
li=sr2[j];
|
||||
sr2[j]=sr2[j+1];
|
||||
sr2[j+1]=li;
|
||||
b=0;
|
||||
}
|
||||
}
|
||||
if(b) break;
|
||||
}
|
||||
for(int i=0;i+1<sr2.size();i++)
|
||||
{
|
||||
if(sr2[i].num==sr2[i+1].num)
|
||||
{
|
||||
sr2.erase(sr2.begin()+i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
for(int i=1;i<=sr2.size();i++) sr2[i].p=i;
|
||||
for(int i=0;i<sr1.size();i++)
|
||||
{
|
||||
for(int j=0;j<sr2.size();j++)
|
||||
{
|
||||
if(sr1[i]==sr2[j].num)
|
||||
{
|
||||
cout<<sr2[j].p+1<<" ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
85
history_source/ccf 基础篇/U3/3.5.3.cpp
Normal file
85
history_source/ccf 基础篇/U3/3.5.3.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include<string>
|
||||
#include<cmath>
|
||||
#define BASE 100000000
|
||||
#define SIZE 8
|
||||
using namespace std;
|
||||
struct bigNum
|
||||
{
|
||||
vector<int>num;
|
||||
bigNum operator=(string b)
|
||||
{
|
||||
num.clear();
|
||||
for(int i=0;i<b.size();i++)
|
||||
{
|
||||
if(i%SIZE==0) num.insert(num.begin(),0);
|
||||
num[0]+=(b[b.size()-1-i]-'0')*pow(10,i%SIZE);
|
||||
}
|
||||
while(num[0]==0&&num.size()>1) num.erase(num.begin());
|
||||
}
|
||||
bigNum operator+(bigNum b)
|
||||
{
|
||||
bigNum a;
|
||||
a.num=num;
|
||||
if(a.num.size()<b.num.size())
|
||||
{
|
||||
bigNum c=a;
|
||||
a=b;
|
||||
b=c;
|
||||
}
|
||||
int ai,bi;
|
||||
int j=0;
|
||||
for(ai=a.num.size()-1,bi=b.num.size()-1;bi>=0;ai--,bi--)
|
||||
{
|
||||
a.num[ai]=a.num[ai]+b.num[bi]+j;
|
||||
j=a.num[ai]/BASE;
|
||||
a.num[ai]=a.num[ai]%BASE;
|
||||
}
|
||||
while(ai>=0&&j)
|
||||
{
|
||||
a.num[ai]+=j;
|
||||
j=a.num[ai]/BASE;
|
||||
a.num[ai]=a.num[ai]%BASE;
|
||||
ai--;
|
||||
}
|
||||
if(j) a.num.insert(a.num.begin(),1);
|
||||
return a;
|
||||
}
|
||||
};
|
||||
ostream& operator<<(ostream &a,bigNum b)
|
||||
{
|
||||
a<<b.num[0];
|
||||
int x;
|
||||
for(int i=1;i<b.num.size();i++)
|
||||
{
|
||||
x=b.num[i];
|
||||
if(x<10) a<<"0000000";
|
||||
else if(x<100) a<<"000000";
|
||||
else if(x<1000) a<<"00000";
|
||||
else if(x<10000) a<<"0000";
|
||||
else if(x<100000) a<<"000";
|
||||
else if(x<1000000) a<<"00";
|
||||
else if(x<10000000) a<<"0";
|
||||
a<<x;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
bigNum ans[n];
|
||||
bigNum a,b;
|
||||
string x;
|
||||
for(int i=0;i<n;i++)
|
||||
{
|
||||
cin>>x;
|
||||
a=x;
|
||||
cin>>x;
|
||||
b=x;
|
||||
ans[i]=a+b;
|
||||
}
|
||||
for(int i=0;i<n;i++) cout<<ans[i]<<endl;
|
||||
return 0;
|
||||
}
|
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;
|
||||
}
|
29
history_source/ccf 基础篇/U7/7.6.1.cpp
Normal file
29
history_source/ccf 基础篇/U7/7.6.1.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
using namespace std;
|
||||
string p,q,r;
|
||||
long long ten(string sr,int j)
|
||||
{
|
||||
long long add=0;
|
||||
for(int i=0;i<sr.size();i++)
|
||||
{
|
||||
add*=j;
|
||||
add+=sr[i]-'0';
|
||||
}
|
||||
return add;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int b;
|
||||
while(true)
|
||||
{
|
||||
cin>>p>>q>>r;
|
||||
for(b=2;b<=16;b++)
|
||||
{
|
||||
if(ten(p,b)*ten(q,b)==ten(r,b)) break;
|
||||
}
|
||||
if(ten(p,b)*ten(q,b)==ten(r,b)) cout<<b<<endl;
|
||||
else cout<<0<<endl;
|
||||
}
|
||||
}
|
||||
|
21
history_source/ccf 基础篇/U7/7.6.2.cpp
Normal file
21
history_source/ccf 基础篇/U7/7.6.2.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include<cstdio>
|
||||
#include<algorithm>
|
||||
using namespace std;
|
||||
int num[100010];
|
||||
int main()
|
||||
{
|
||||
freopen("data.txt","r",stdin);
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
for(int i=0;i<n;i++) scanf("%d",num+i);
|
||||
int max,maxn;
|
||||
max=maxn=num[0];
|
||||
for(int i=1;i<n;i++)
|
||||
{
|
||||
if(maxn<0) maxn=num[i];
|
||||
else maxn+=num[i];
|
||||
if(maxn>max) max=maxn;
|
||||
}
|
||||
printf("%d\n",max);
|
||||
return 0;
|
||||
}
|
32
history_source/ccf 基础篇/U7/7.6.3.cpp
Normal file
32
history_source/ccf 基础篇/U7/7.6.3.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include<cstdio>
|
||||
int n,a[305][305],y[305][305],maxn,max,i,j,k;
|
||||
int main()
|
||||
{
|
||||
scanf("%d",&n);
|
||||
for(i=0;i<n;i++)
|
||||
for(j=0;j<n;j++)
|
||||
scanf("%d",&(a[j][i]));
|
||||
for(i=0;i<n;i++)
|
||||
for(j=1;j<=n;j++)
|
||||
y[i][j]=y[i][j-1]+a[i][j-1];
|
||||
for(i=1;i<=n;i++)
|
||||
for(j=i;j<=n;j++)
|
||||
{
|
||||
maxn=0;
|
||||
for(k=0;k<n;k++)
|
||||
{
|
||||
if(maxn<0) maxn=y[k][j]-y[k][i-1];
|
||||
else maxn+=y[k][j]-y[k][i-1];
|
||||
if(maxn>max) max=maxn;
|
||||
}
|
||||
}
|
||||
printf("%d\n",max);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
4
|
||||
0 -2 -7 0
|
||||
9 2 -6 2
|
||||
-4 1 -4 2
|
||||
-1 8 0 -2
|
||||
*/
|
48
history_source/ccf 基础篇/U7/7.6.4.cpp
Normal file
48
history_source/ccf 基础篇/U7/7.6.4.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include<cstdio>
|
||||
#include<cstdlib>
|
||||
#define MAXN 550
|
||||
#define MAX MAXN/2-1
|
||||
using namespace std;
|
||||
bool isp[MAXN],use[MAX+1];
|
||||
int ans[MAX];
|
||||
int x;
|
||||
void search(int n)
|
||||
{
|
||||
if(n==x)
|
||||
{
|
||||
if(isp[ans[x-1]+ans[0]])
|
||||
{
|
||||
for(int i=0;i<x;i++) printf("%d ",ans[i]);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
for(int i=1;i<=x;i++)
|
||||
{
|
||||
if((!use[i])&&isp[ans[n-1]+i])
|
||||
{
|
||||
use[i]=1;
|
||||
ans[n]=i;
|
||||
search(n+1);
|
||||
use[i]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
for(int i=2;i<MAXN;i++) isp[i]=1;
|
||||
for(int i=2;i<MAXN;i++)
|
||||
if(isp[i])
|
||||
for(int j=2;j*i<MAXN;j++)
|
||||
isp[j*i]=0;
|
||||
// scanf("%d",&x);
|
||||
x=20;
|
||||
if(x&1)
|
||||
{
|
||||
printf("-1\n");
|
||||
return 0;
|
||||
}
|
||||
use[1]=1;
|
||||
ans[0]=1;
|
||||
search(1);
|
||||
return 0;
|
||||
}
|
19
history_source/ccf 基础篇/U8/8.6.1.cpp
Normal file
19
history_source/ccf 基础篇/U8/8.6.1.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int zd(int a,int b)
|
||||
{
|
||||
return (b==0)?a:zd(b,a%b);
|
||||
}
|
||||
int zx(int a,int b)
|
||||
{
|
||||
return a*b/zd(a,b);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n,m;
|
||||
while(true)
|
||||
{
|
||||
cin>>n>>m;
|
||||
cout<<zx(n,m)<<endl;
|
||||
}
|
||||
}
|
41
history_source/ccf 基础篇/U8/8.6.2.cpp
Normal file
41
history_source/ccf 基础篇/U8/8.6.2.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include<cstdio>
|
||||
using namespace std;
|
||||
unsigned long long gcd(unsigned long long m,unsigned long long n)
|
||||
{
|
||||
int x=1;
|
||||
unsigned long long t;
|
||||
begin:if(m==n) return x*m;
|
||||
if(m<n)
|
||||
{
|
||||
t=m,m=n,n=t;
|
||||
goto begin;
|
||||
}
|
||||
if(m&1)
|
||||
{
|
||||
if(n&1)
|
||||
{
|
||||
t=n;
|
||||
n=m-n;
|
||||
m=t;
|
||||
goto begin;
|
||||
}
|
||||
n=n>>1;
|
||||
goto begin;
|
||||
}
|
||||
if(n&1)
|
||||
{
|
||||
m=m>>1;
|
||||
goto begin;
|
||||
}
|
||||
x=x*2;
|
||||
m=m>>1;
|
||||
n=n>>1;
|
||||
goto begin;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
unsigned long long n,m;
|
||||
scanf("%lld%lld",&n,&m);
|
||||
printf("%lld\n",gcd(n,m));
|
||||
return 0;
|
||||
}
|
41
history_source/ccf 基础篇/U8/8.6.3.cpp
Normal file
41
history_source/ccf 基础篇/U8/8.6.3.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include<cstdio>
|
||||
using namespace std;
|
||||
unsigned long long gcd(unsigned long long m,unsigned long long n)
|
||||
{
|
||||
int x=1;
|
||||
unsigned long long t;
|
||||
begin:if(m==n) return x*m;
|
||||
if(m<n)
|
||||
{
|
||||
t=m,m=n,n=t;
|
||||
goto begin;
|
||||
}
|
||||
if(m&1)
|
||||
{
|
||||
if(n&1)
|
||||
{
|
||||
t=n;
|
||||
n=m-n;
|
||||
m=t;
|
||||
goto begin;
|
||||
}
|
||||
n=n>>1;
|
||||
goto begin;
|
||||
}
|
||||
if(n&1)
|
||||
{
|
||||
m=m>>1;
|
||||
goto begin;
|
||||
}
|
||||
x=x*2;
|
||||
m=m>>1;
|
||||
n=n>>1;
|
||||
goto begin;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
unsigned long long n,m;
|
||||
scanf("%lld%lld",&n,&m);
|
||||
printf("%lld\n",gcd(n,m));
|
||||
return 0;
|
||||
}
|
33
history_source/ccf 基础篇/U8/8.6.4.cpp
Normal file
33
history_source/ccf 基础篇/U8/8.6.4.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include<cstdio>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
bool x;
|
||||
int t;
|
||||
int m;
|
||||
scanf("%d",&t);
|
||||
int sr[t];
|
||||
for(int i=0;i<t;i++) scanf("%d",sr+i);
|
||||
for(int i=0;i<t;i++)
|
||||
{
|
||||
x=0;
|
||||
for(int j=2;j<=sr[i];j++)
|
||||
{
|
||||
if(sr[i]%j==0)
|
||||
{
|
||||
if(x) printf("*");
|
||||
m=0;
|
||||
while(sr[i]%j==0)
|
||||
{
|
||||
m++;
|
||||
sr[i]/=j;
|
||||
}
|
||||
printf("%d",j);
|
||||
if(m>1) printf("^%d",m);
|
||||
x=1;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user