T1
[前缀和,差分]
求二维前缀和然后大概差分一下就好了?
【code】
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; #define ll long long #define File "wireless" inline void file(){ freopen(File".in","r",stdin); freopen(File".out","w",stdout); } inline int read(){ int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();} while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();} return x*f; } const int mxn = 130; int d,n; int s[mxn][mxn]; int a[mxn][mxn]; inline int Q(int x_1,int y_1,int x_2,int y_2){ return s[x_2][y_2] - s[x_1-1][y_2] - s[x_2][y_1-1] + s[x_1-1][y_1-1]; } int cnt,ans; int main(){ file(); d = read(),n = read(); for(int i = 1;i <= n; ++i){ int x,y,k; x = read(),y = read(),k = read(); a[x][y] = k; } // s[0][0] = a[0][0]; for(int i = 0;i <= 128; ++i) for(int j = 0;j <= 128; ++j) s[i][j] = (s[i][j-1] + s[i-1][j] - s[i-1][j-1] + a[i][j]); // ,printf("%d\n",s[i][j]); // printf("%d\n",ans); for(int i = 0;i <= 128; ++i){ for(int j = 0;j <= 128; ++j){ int x_1,y_1,x_2,y_2; x_1 = (i-d >= 0) ? (i-d) : 0; y_1 = (j-d >= 0) ? (j-d) : 0; x_2 = (i+d <= 128) ? (i+d) : 128; y_2 = (j+d <= 128) ? (j+d) : 128; int t = Q(x_1,y_1,x_2,y_2); if(t == ans) cnt++; else if(t > ans) ans = t,cnt = 1; } } printf("%d %d\n",cnt,ans); return 0; }
T2
[Bfs]
通过建反图判断每个点是否能到达终点。
通过枚举每个能达到终点的点,判断与之相连的边连接的点是否能出现在路径中。
最后bfs求出起点到终点的距离即可。
【code】
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; #define ll long long #define File "road" inline void file(){ freopen(File".in","r",stdin); freopen(File".out","w",stdout); } inline int read(){ int x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();} while(ch >= '0' && ch <= '9'){x = (x<<1) + (x<<3) + ch-'0'; ch = getchar();} return x*f; } const int mxn = 1e4 + 10; int n,m; bool v1[mxn],v2[mxn];//是否能出现在路途中。是否能到达终点。 int dis[mxn]; vector<int>E1[mxn]; vector<int>E2[mxn]; #define pb push_back int st,ed; queue<int> q; int main(){ // file(); n = read(),m = read(); for(int i = 1;i <= m; ++i){ int x = read(),y = read(); E1[x].pb(y),E2[y].pb(x); } st = read(),ed = read(); v2[ed] = 1; q.push(ed); while(q.size()){ int x = q.front(); q.pop(); for(int i = E2[x].size()-1; i >= 0; --i){ int y = E2[x][i]; if(!v2[y]){ q.push(y); v2[y] = 1; } } } if(!v2[st]){ puts("-1"); return 0; } for(int i = 1;i <= n; ++i){ if(v2[i]){ v1[i] = 1; for(int j = E1[i].size()-1; j >= 0; --j){ int y = E1[i][j]; if(!v2[y]){ v1[i] = 0; break; } } } } dis[st] = 1; q.push(st); while(q.size()){ int x = q.front(); q.pop(); if(x == ed){ printf("%d\n",dis[ed]-1); return 0; } for(int i = E1[x].size()-1; i >= 0; --i){ int y = E1[x][i]; if(v1[y] && !dis[y]){ dis[y] = dis[x] + 1; q.push(y); } } } puts("-1"); return 0; }
T3
[数学]
读入取模。秦九韶公式。
【code】
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; #define ll long long #define File "equation" inline void file(){ freopen(File".in","r",stdin); freopen(File".out","w",stdout); } const int mod = 998244353; const int mxn = 110; inline ll read(){ ll x = 0,f = 1; char ch = getchar(); while(ch < '0' || ch > '9'){if(ch=='-')f = -1; ch = getchar();} while(ch >= '0' && ch <= '9'){x = ((x<<1)%mod + (x<<3)%mod + ch-'0')%mod; ch = getchar();} return x*f; } ll n,m; ll a[mxn],b[mxn]; ll tot(0); inline bool J(ll x){ ll s(0); for(ll i = n; i; --i) s = ((s + a[i])*x) % mod; s = (s+a[0]) % mod; return s==0; }//秦九韶公式的判断。返回得到的s是否等于0 int main(){ file(); n = read(),m = read(); for(ll i = 0;i <= n; ++i) a[i] = read(); for(ll i = 1;i <= m; ++i){ if(J(i)) b[++tot] = i;//记录答案 } printf("%lld\n",tot); for(ll i = 1;i <= tot; ++i) printf("%lld\n",b[i]); return 0; }
我又预感因为交题交得慢我今天要ak掉rating。