A:题链
#include<bits/stdc++.h> using namespace std; int n,m,a,b; long double ans; int main () { scanf("%d %d",&n,&m); ans=1e9; for(int i=1;i<=n;i++) { scanf("%d %d",&a,&b); ans=min(ans,(long double)1.0*a/b); } printf("%.9Lf",ans*m); }
B:题链 打表
#include <bits/stdc++.h> using namespace std; #define inf 1e10 //#define getchar nc //#define min(a,b) ((a)<(b)?(a):(b)) //#define max(a,b) ((a)>(b)?(a):(b)) #define sight(c) (‘0‘<=c&&c<=‘9‘) //#define swap(a,b) a^=b,b^=a,a^=b #define LL long long #define deg printf #define dput put #define dputc putchar #define db double #define eho(x) for(int i=head[x];i;i=net[i]) int xx; inline char nc(){ static char buf[1000000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++; } inline void read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } set<LL> S; vector<LL> V; void dfs(LL x, int y) { if (x > inf) return; if (!y) S.insert(x); for (int i=1;i<=min(9,y);i++) dfs(x * 10 + i, y - i); if (x) dfs(x * 10, y); } int main(void) { dfs(0, 10); read(xx); for (auto x : S) V.push_back(x); printf("%lld\n", V[xx - 1]); return 0; }
C:题链
记得特判1
#include <bits/stdc++.h> using namespace std; //#define getchar nc //#define min(a,b) ((a)<(b)?(a):(b)) //#define max(a,b) ((a)>(b)?(a):(b)) #define sight(c) (‘0‘<=c&&c<=‘9‘) //#define swap(a,b) a^=b,b^=a,a^=b #define LL long long #define deg printf #define dput put #define dputc putchar #define db double #define eho(x) for(int i=head[x];i;i=net[i]) inline char nc(){ static char buf[1000000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++; } inline void read(LL &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } inline void read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } int n, m, k, ans, a[2005][2005], b[2005][2005], c[2005][2005]; char s[2005][2005]; bool rr1(int x, int y) { return y+k-1>m?0:b[x][y + k - 1] - b[x][y - 1] == k; } bool rr2(int x, int y) { return x+k-1>n?0:c[x + k - 1][y] - c[x - 1][y] == k;} int main() { read(n);read(m);read(k); for(int i=1;i<=n;i++) scanf("%s", s[i] + 1); for (int i=1;i<=n;i++)for (int j=1;j<=m;j++) a[i][j]=s[i][j]==‘.‘?1:0; for(int i=1;i<=n;i++) for (int j=1;j<=m;j++) b[i][j] = b[i][j - 1] + a[i][j]; for(int i=1;i<=n;i++) for (int j=1;j<=m;j++) c[i][j] = c[i - 1][j] + a[i][j]; for(int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (rr1(i, j)) ans++; if (k^1) {for (int i=1;i<=n;i++)for(int j=1;j<=m;j++) if (rr2(i, j)) ans++;} printf("%d\n", ans); return 0; }
D:题链
做dp即可
//#pragma GCC optimize("-O2") #include<bits/stdc++.h> #define LL long long #define deg printf #define sight(c) (‘0‘<=c&&c<=‘9‘) #define N 600007 #define dput put #define dputc putchar #define db double #define eho(x) for(int i=head[x];i;i=net[i]) int in[N],x,y,tot,head[N],net[N],fall[N],n,m,f[N][26],ans,a[N],tog; char ch[N]; using namespace std; queue<int> Q; inline void add(int x,int y){ fall[++tot]=y; net[tot]=head[x]; head[x]=tot; } inline void read(int &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } void write(int x){if (x<10) {putchar(‘0‘+x); return;} write(x/10); putchar(‘0‘+x%10);} inline void writeln(int x){ if (x<0) putchar(‘-‘),x*=-1; write(x); putchar(‘\n‘); } inline void writel(int x){ if (x<0) putchar(‘-‘),x*=-1; write(x); putchar(‘ ‘); } signed main() { read(n); read(m); scanf("%s",ch+1); while (m--) { read(x),read(y); add(x,y); in[y]++; } for (int i=1;i<=n;i++) if (!in[i]) { Q.push(i); f[i][ch[i]-‘a‘]=1;} while (!Q.empty()) { x=a[++tog]=Q.front(); Q.pop(); eho(x) { in[fall[i]]--; if (!in[fall[i]]) Q.push(fall[i]); } } if (tog!=n) { printf("-1\n"); return 0; } for (int i=1;i<=n;i++) { x=a[i]; eho(x) { for (int j=0;j<26;j++) { f[fall[i]][j]=max(f[fall[i]][j],f[x][j]+(ch[fall[i]]-‘a‘==j)); if (f[fall[i]][j]>ans) ans=f[fall[i]][j]; } } } printf("%d\n",ans); return 0; }
E:题链
注意到p很小,那么对p暴力
#include <bits/stdc++.h> using namespace std; #define sight(c) (‘0‘<=c&&c<=‘9‘) #define LL long long #define deg printf #define dput put #define dputc putchar #define db double #define eho(x) for(int i=head[x];i;i=net[i]) inline char nc(){ static char buf[1000000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++; } LL a, b, p, x, z, rrsb, rrsbrrsb, ans,c; inline void read(LL &x){ static char c; for (c=getchar();!sight(c);c=getchar()); for (x=0;sight(c);c=getchar())x=x*10+c-48; } inline LL qsm(LL x, LL y) { static LL anw; for (anw=1;y;y>>=1,x=x*x%p) if (y&1) anw=anw*x%p; return anw; } void write(LL x){if (x<10) {putchar(‘0‘+x); return;} write(x/10); putchar(‘0‘+x%10);} inline void writeln(LL x){ if (x<0) putchar(‘-‘),x*=-1; write(x); putchar(‘\n‘); } inline void writel(LL x){ if (x<0) putchar(‘-‘),x*=-1; write(x); putchar(‘ ‘); } inline void Mo(LL &x){ if (x<0) x=x%p+p; if (x>=p) x%=p; } void gg(int i) { rrsb-=i; Mo(rrsb); rrsb*=qsm(p-1,p-2); Mo(rrsb); } void init() { read(a);read(b);read(p);read(x); z = 1; for(int i=1;i<p;i++) { z=z*a%p; rrsb=qsm(z,p-2)*b%p; gg(i); rrsbrrsb=(p-1)*rrsb+i; if (rrsbrrsb>x) continue; ans+=(x-rrsbrrsb)/(p*(p-1))+1; } } int main() { init(); writeln(ans); return 0; }