打完涨了20分……
算法选修课就学会了dfs……如果有期末复习的这种劲头,其他算法估计早就学会了(
A Forbidden Integer
这个还WA了三发……
signed main(){
IOS;
int n,k,x;
bool f=1;
cf{
cin>>n>>k>>x;
if(k==1)cout<<"NO"<<endl;
else{
if(x==1){
if(n%2==0){
cout<<"YES"<<endl;
cout<<n/2<<endl;
fer(i,0,n/2)cout<<"2"<<" ";
cout<<endl;
}else{
if(k==2)cout<<"NO"<<endl;
else {
cout<<"YES"<<endl;
cout<<n/2<<endl;
fer(i,0,n/2-1)cout<<"2"<<" ";
cout<<3<<endl;
}
}
}else {
cout<<"YES"<<endl;
cout<<n<<endl;
fer(i,0,n)cout<<"1"<<" ";
cout<<endl;
}
}
}
return 0;
}
B Come Together
signed main(){
IOS;
int xa,ya,xb,yb,xc,yc;
int res;
cf{
cin>>xa>>ya>>xb>>yb>>xc>>yc;
xb-=xa;yb-=ya;
xc-=xa;yc-=ya;
res=1;
if((xb>0&&xc>0)||(xb<0&&xc<0))res+=min(abs(xb),abs(xc));
if((yb>0&&yc>0)||(yb<0&&yc<0))res+=min(abs(yb),abs(yc));
cout<<res<<endl;
}
return 0;
}
C Strong Password
好好读题……
dfs回溯+剪枝+优化也没过……tle on test 7,不过有人dfs过了,不知有无被hack
string s,l,r;
int m;
bool f;
string res="";
pair<int,int> check(int starti,int startj){
int finali=0,finalj=0;
int i=starti+1,j=startj+1;
while(i<s.size()&&j<res.size()){
if(s[i]==res[j]){
finali=i,finalj=j;
j++;
}
i++;
}
if(j!=res.size())f=1;
return make_pair(finali,finalj);
}
void dfs(int t,int starti,int startj){
if(t==m){
//cout<<res<<endl;
check(starti,startj);
return;
}
fer(i,l[t]-'0',r[t]-'0'+1){
char tmp=i+'0';
res+=tmp;
pair<int,int> pr;
pr=check(starti,startj);
if(f){
res="";
return;
}
else {
dfs(t+1,pr.first,pr.second);
if(f){
res="";return;
}
res.pop_back();
}
}
}
signed main(){
IOS;
cf{
cin>>s;
cin>>m;
cin>>l>>r;
f=0;
dfs(0,-1,-1);
if(f)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
D Rating System
贪心