9.6线上模拟
()
T1 纯纯模拟 但是超时了()极度怀疑是数据类型的锅:
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <climits> 5 #include <cassert> 6 #include <cmath> 7 #include <cstring> 8 #include <cstdlib> 9 #include <cctype> 10 #include <utility> 11 #include <set> 12 #include <map> 13 #include <stack> 14 #include <queue> 15 #include <vector> 16 #define int long long 17 #define ll long long 18 #define ull unsigned long long 19 #define re register 20 #define lowbit(x) x & (-x) 21 #define gcd(a,b) _gcd(a,b) 22 #define mid ((l + r) >> 1) 23 #define rep(i,a,b) for(re int i(a);i <= b;i ++) 24 #define rrep(i,a,b) for(re int i(a);i >= b;i --) 25 using namespace std; 26 inline int read(){ 27 re int x = 0,f = 1; 28 re char ch = getchar(); 29 while(ch < '0' || ch > '9'){ 30 if(ch == '-') f = -1; 31 ch = getchar(); 32 } 33 while(ch >= '0' && ch <= '9'){ 34 x = (x << 3) + (x << 1) + (ch ^ 48); 35 ch = getchar(); 36 } 37 return x * f; 38 } 39 const int M = 1e5 + 1; 40 struct A{ 41 double a,b; 42 }a[M]; 43 double ans = 0.0; 44 int n; 45 signed main(){ 46 freopen("money.in","r",stdin); 47 freopen("money.out","w",stdout); 48 n = read(); 49 rep(i,1,n){ 50 scanf("%lf%lf",&a[i].a,&a[i].b); 51 ans += a[i].a * a[i].b / 10; 52 } 53 printf("%.2lf\n",ans); 54 return 0; 55 }
T2 待更。。。。。
T3 半联通
由于单向(定义)
所以最大的半连通子图肯定是一条链
那就先缩点 点权为分量顶点数 然后去重边
f[i]表示到第i的最长路径 ans[i]表示到第i个点的最长路径数量 rcd[]计入度
拓扑序DP跑最长链
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <climits> 5 #include <cassert> 6 #include <cmath> 7 #include <cstring> 8 #include <cstdlib> 9 #include <cctype> 10 #include <utility> 11 #include <set> 12 #include <map> 13 #include <queue> 14 #include <vector> 15 #define int long long 16 #define ll long long 17 #define ull unsigned long long 18 #define re register 19 #define lowbit(x) x & (-x) 20 #define gcd(a,b) _gcd(a,b) 21 #define mid ((l + r) >> 1) 22 #define rep(i,a,b) for(re int i(a);i <= b;i ++) 23 #define rrep(i,a,b) for(re int i(a);i >= b;i --) 24 using namespace std; 25 inline int read(){ 26 re int x = 0,f = 1; 27 re char ch = getchar(); 28 while(ch < '0' || ch > '9'){ 29 if(ch == '-') f = -1; 30 ch = getchar(); 31 } 32 while(ch >= '0' && ch <= '9'){ 33 x = (x << 3) + (x << 1) + (ch ^ 48); 34 ch = getchar(); 35 } 36 return x * f; 37 } 38 const int M = 2000010; 39 int n,m,p; 40 int cnt = 0; 41 int top; 42 int tmp; 43 int head[M]; 44 int tot; 45 struct node{ 46 int s; 47 int to; 48 int next; 49 }b[M]; 50 node e[M]; 51 struct A{ 52 int x; 53 int y; 54 }a[M]; 55 int head1[M]; 56 int tot1 = 0; 57 int rcd[M]; 58 int ans[M]; 59 int f[M]; 60 int c[M]; 61 int st[M]; 62 int low[M]; 63 int dfn[M]; 64 int d[M]; 65 bool vis[M]; 66 queue<int> q; 67 inline void add(int x,int y){b[++ tot] = (node){x,y,head[x]};head[x] = tot;} 68 inline void add1(int x,int y){e[++ tot1] = (node){x,y,head1[x]};head1[x] = tot1;} 69 inline void tarjan(int x){ 70 low[x] = dfn[x] = ++ cnt; 71 st[++ top] = x; 72 vis[x] = 1; 73 for(re int i(head[x]);i;i = b[i].next){ 74 int y = b[i].to; 75 if(!dfn[y]){ 76 tarjan(y); 77 low[x] = min(low[x],low[y]); 78 } 79 else if(vis[y]) low[x] = min(low[x], dfn[y]); 80 } 81 if(low[x] == dfn[x]){ 82 tmp ++; 83 do{ 84 c[st[top]] = tmp; 85 d[tmp] ++; 86 vis[st[top]] = 0; 87 top --; 88 } 89 while(st[top + 1]!= x); 90 } 91 return; 92 } 93 int maxx = 0; 94 inline bool cmp(A x, A y){return x.x == y.x ? x.y < y.y : x.x < y.x;} 95 signed main(){ 96 freopen("semi.in","r",stdin); 97 freopen("semi.out","w",stdout); 98 n = read(); 99 m = read(); 100 p = read(); 101 rep(i,1,m){ 102 a[i].x = read(); 103 a[i].y = read(); 104 add(a[i].x,a[i].y); 105 } 106 rep(i,1,n) if(!dfn[i]) tarjan(i); 107 rep(i,1,m) a[i].x = c[a[i].x],a[i].y = c[a[i].y]; 108 sort(a + 1,a + 1 + m,cmp); 109 rep(i,1,m) if(a[i].x!= a[i].y && (a[i].x != a[i-1].x || a[i].y != a[i-1].y)) add1(a[i].x, a[i].y), rcd[a[i].y] ++; 110 rep(i,1,tmp) { 111 ans[i] = 1,f[i] = d[i]; 112 if (!rcd[i]) q.push(i); 113 } 114 while(!q.empty()){ 115 int x = q.front(); 116 q.pop(); 117 maxx = max(maxx, f[x]); 118 for(re int i(head1[x]);i;i = e[i].next){ 119 int y = e[i].to; 120 rcd[y] --; 121 if(f[y] < f[x] + d[y]){ 122 f[y] = f[x] + d[y]; 123 ans[y] = ans[x]; 124 } 125 else if(f[y] == f[x]+d[y]) ans[y] = (ans[y] + ans[x]) % p; 126 if(!rcd[y]) q.push(y); 127 } 128 } 129 cnt = 0; 130 rep(i,1,tmp) if(maxx == f[i]) cnt = (cnt + ans[i]) % p; 131 printf("%d\n%d",maxx,cnt % p); 132 return 0; 133 }
寄。。。。。。。
待完善。。。。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】