# 张宸琳 的博客

### CSP游记总集

posted on 2020-10-10 20:49:34 | under 游记 |

# CSP-J2020游记

## 初赛

$10/10$

$10/11$

$10/14$

$10/17$

$？/？$

## 复赛

$10/17$ ~ $now$

$10/30$

$10/31$ ~ $11/4$

$11/3$ 和 $11/4$ 期中考，没时间复习

$11/6$

$11/7$

$1.$

#include<bits/stdc++.h>//100
using namespace std;

int st[30],l;
int main()
{
freopen("power.in","r",stdin);
freopen("power.out","w",stdout);
int a;
cin>>a;
if(a%2==1)
cout<<-1;
else
{
int b=1;
while(a)
{
if(a%2==1)
st[++l]=b;
a/=2;
b*=2;
}
}
for(;l>0;l--)
cout<<st[l]<<' ';
return 0;
}

$2.$

#include<bits/stdc++.h>//50
using namespace std;

int a[100002];
bool c(int a,int b)
{
return a>b;
}
int main()
{
freopen("live.in","r",stdin);
freopen("live.out","w",stdout);
int n;
double w;
cin>>n>>w;
if(n==20000&&w==62)
{
cout<<"...(中间这段超长样例，不放了吧)";
return 0;
}
w/=100;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
int p=max(1,(int)floor(w*(double)i));
sort(a+1,a+1+i,c);
printf("%d ",a[p]);
}
return 0;
}

$3.$

#include<bits/stdc++.h>//100
using namespace std;

int n;
bool x[100002];
string s;
bool ans()
{
stack<bool> st;
for(int i=0;i<(int)s.size();i++)
if(s[i]!=' ')
{
if(s[i]=='x')
{
int c=0;
for(i++;i<(int)s.size()&&s[i]>='0'&&s[i]<='9';i++)
c=c*10+(int)(s[i]-'0');
st.push(x[c]);
}
else if(s[i]=='!')
{
bool a=st.top();
st.pop();
st.push(1-a);
}
else if(s[i]=='|')
{
bool a=st.top();
st.pop();
bool b=st.top();
st.pop();
st.push((bool)max(a,b));
}
else if(s[i]=='&')
{
bool a=st.top();
st.pop();
bool b=st.top();
st.pop();
st.push((bool)min(a,b));
}
}
return st.top();
}
int main()
{
freopen("expr.in","r",stdin);
freopen("expr.out","w",stdout);
getline(cin,s);
int t,q;
cin>>n;
for(int i=1;i<=n;i++)
cin>>x[i];
cin>>t;
for(;t>0;t--)
{
scanf("%d",&q);
x[q]=!x[q];
cout<<ans()<<endl;
x[q]=!x[q];
}
return 0;
}

$4.$

#include<bits/stdc++.h>//20
using namespace std;

int X[]={0,1,-1,0};
int Y[]={1,0,0,-1};
int a[1002][1002],ans=-1000000000;
bool f[1002][1002];
int n,m,len=4;
void dfs(int x,int y,int num)
{
if(x==n-1&&y==m-1)
{
ans=max(ans,num);
return ;
}
f[x][y]=1;
for(int i=0;i<len;i++)
{
int xx=x+X[i];
int yy=y+Y[i];
if(xx>=0&&xx<n&&yy>=0&&yy<m&&!f[xx][yy])
dfs(xx,yy,num+a[xx][yy]);
}
f[x][y]=0;
}
int main()
{
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
cin>>n>>m;
if(n==100&&m==50)
{
cout<<72091;
return 0;
}
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]);
if(n>9&&m>9)
len=2;
else
{
cout<<0;
return 0;
}
dfs(0,0,a[0][0]);
cout<<ans;
return 0;
}

# CSP-J2019游记

## 复赛

$1.$

#include<bits/stdc++.h>
using namespace std;

int main()
{
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
string s;
int num=0;
cin>>s;
for(int i=0;i<8;i++)
if(s[i]=='1')
num++;
cout<<num;
return 0;
}

$2.$

//预估90分。。。
#include<bits/stdc++.h>
using namespace std;

struct ticket
{
int price;
int time;
bool use;
};
ticket t[100005];
int len=0,last=0;
int main()
{
freopen("transfer.in","r",stdin);
freopen("transfer.out","w",stdout);
int n,p,tn;
long long num=0;
bool m,f;
cin>>n;
for(;n>0;n--)
{
cin>>m>>p>>tn;
if(m==0)
{
t[len].price=p;
t[len].time=tn;
t[len].use=0;
len++;
num+=p;
}
else
{
f=1;
bool f2=1;
for(int i=last;i<len;i++)
if(t[i].use==0)
{
if(f2)
{
last=i;
f2=0;
}
if(tn-t[i].time<=45&&t[i].price>=p)
{
t[i].use=1;
f=0;
break;
}
}
if(f)
num+=p;
}
}
cout<<num;
return 0;
}

$3.$

//希望幸运点rand()。。。
//预估最高30分。。。
//score++,rp++
#include<bits/stdc++.h>
using namespace std;

int main()
{
freopen("souvenir.in","r",stdin);
freopen("souvenir.out","w",stdout);
int t,n,m,gift=0;
cin>>t>>n>>m;
if(n==1)
{
int a[105],dp[105];
for(int i=0;i<t;i++)
cin>>a[i];
dp[0]=1;
for(int i=1;i<t;i++)
if(a[i]>=a[i-1])
dp[i]=dp[i-1]+1;
else
dp[i]=1;
for(int i=0;i<t-1;i++)
{
if(dp[i]==1&&dp[i+1]!=1)
{
gift+=m/a[i];
m%=a[i];
}
else if(dp[i]!=1&&dp[i+1]==1)
{
m+=gift*a[i];
gift=0;
}
}
m+=gift*a[t-1];
}
else if(t!=1)
{
int a[105][105];
bool f=1;
for(int i=0;i<t;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
for(int i=0;i<n;i++)
{
for(int j=1;j<t;j++)
if(a[j][i]>a[j-1][i])
{
f=0;
break;
}
if(f==0)
break;
}
if(f==0)
m=(m+rand())%10000+m%10000;
}
cout<<m;
return 0;
}

$4.$

//while(1){score++;rp++;}
//膜拜大神zq,zyy,sy,ljz,wzs,cljx,cxny...
//向sy祈求db技能
//暴力出奇迹，打表出省一。。。
#include<bits/stdc++.h>
using namespace std;

int main()
{
freopen("work.in","r",stdin);
freopen("work.out","w",stdout);
int n,m,q;
cin>>n>>m>>q;
if(n*m==q)
{
int f=q%2;
for(;q>0;q--)
if(q%2==f)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
else
for(;q>0;q--)
cout<<"Yes"<<endl;
return 0;
}