#include<iostream>#include<cstdio>
using namespace std;intmain(){int n, x;
cin >> n >> x;int cnt =0;for(int i =1; i <= n; i ++){for(int j = i; j; j /=10){if(j %10== x) cnt ++;}}
cout << cnt << endl;return0;}
表达式求值
#include<iostream>#include<cstdio>
using namespace std;constint N =1e5+10, MOD =10000;int stk[N], tt;intmain(){int a;char op;
cin >> a;
stk[++tt]= a % MOD;while(cin >> op >> a){if(op =='+') stk[++tt]= a % MOD;else stk[tt]= a % MOD * stk[tt]% MOD;}int ans =0;while(tt !=0){
ans =(ans + stk[tt --])% MOD;}
cout << ans << endl;return0;}
小朋友的数字
#include<iostream>#include<cstdio>#defineLLlonglong
using namespace std;constint N =1e6+10;int n, p, x;
LL sum, t[N], f[N];//特征值, 分数 intmain(){scanf("%d %d",&n,&p);
t[0]=-1e18;for(int i =1; i <= n; i ++){scanf("%d",&x);
sum += x;
t[i]=max(t[i-1], sum);//前i个数字中的最大字段和 if(sum <0) sum =0;}
f[1]= t[1]% p;//题意
f[2]=(f[1]+ t[1])% p;//题意 for(int i =3; i <= n; i ++){
f[i]=max(f[i-1], t[i-1]+ f[i-1])% p;}if(f[1]>0) cout << f[n];else cout <<max(f[1], f[n]);return0;}
车站分级 90分代码
#include<iostream>#include<cstdio>#include<cstring>#include<queue>
using namespace std;constint N =1005;int n, m;int a[N], lv[N], du[N], e[N][N];
queue <int> q;voidtopsort(){for(int i =1; i <= n; i ++){if(du[i]==0){
q.push(i);
lv[i]=1;}}while(q.size()){int front = q.front();
q.pop();for(int j =1; j <= n; j ++){if(e[front][j]){
du[j]--;if(du[j]==0){
q.push(j);
lv[j]= lv[front]+1;}}}}}intmain(){scanf("%d %d",&n,&m);for(int i =1; i <= m; i ++){int s, b, f, x;//共s个站点,起点,终点 scanf("%d",&s);memset(a,0,sizeof(a));for(int j =1; j <= s; j ++){scanf("%d",&x);
a[x]=1;//本趟列车停靠x站if(j ==1) b = x;if(j == s) f = x;}for(int j = b; j <= f; j ++){for(int k = b +1; k <= f -1; k ++){if(a[j]&&!a[k]&&!e[k][j]){
e[k][j]=1;//level j > level k
du[j]++;}}}}topsort();int ans =0;for(int i =1; i <= n; i ++){
ans =max(ans, lv[i]);}
cout << ans;return0;}
车站分级 100分代码
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<set>
using namespace std;constint N =1005;int n, m;int a[N], lv[2*N], du[2*N], e[2*N][2*N];
queue <int> q;voidtopsort(){for(int i =1; i <= n + m; i ++){//n个真实站台 + m个虚拟站台 if(du[i]==0){
q.push(i);if(i <= n) lv[i]=1;//真实站台的最低等级为1,虚拟站台等级均为0 }}while(q.size()){int front = q.front();
q.pop();for(int j =1; j <= n + m; j ++){if(e[front][j]){
du[j]--;if(du[j]==0){
q.push(j);
lv[j]= lv[front]+(front > n);//虚拟站台 -> 真实站台,等级+1 }}}}}intmain(){scanf("%d %d",&n,&m);for(int i =1; i <= m; i ++){int s, b, f, x;//共s个站点,起点,终点 scanf("%d",&s);memset(a,0,sizeof(a));for(int j =1; j <= s; j ++){scanf("%d",&x);
a[x]=1;//本趟列车停靠x站if(j ==1) b = x;if(j == s) f = x;}for(int j = b; j <= f; j ++){if(a[j]==1){
e[n+i][j]=1;//虚拟站台n+i -> j站台
du[j]++;}else{
e[j][n+i]=1;//j站台 -> 虚拟站台n+i
du[n+i]++;}}}topsort();int ans =0;for(int i =1; i <= n; i ++) ans =max(ans, lv[i]);
cout << ans;return0;}