csp-s模拟3

A. 奇观

观察到 \(c\)\(f\) 互不影响,所以分开算就行,枚举相连的边太多了,会 \(T\),所以我们把总情况找出来,减去删去的边的

方案数即可,记 \(f_{u,x}\) 表示 \(u\) 节点往后跟 \(x\) 个长度的方案数,有 \(f_{u,x}=\sum_{x->y} \limits f_{y,x-1}\)

边界 \(f_{u,1}=\) 其度数,这是 \(c\) 的,\(f\) 就是长度为 \(3\) 的链后面随便取俩点

点击查看代码
#include<bits/stdc++.h>
#define int long long
const int mod=998244353;
const int maxn=1e5+10;
using namespace std;
int n,m,sum,ans,temp,in[maxn];
int f[maxn][4];
vector<int>q[maxn];
unordered_map<int,int>a[maxn]; signed main()
{freopen("a.in","r",stdin);freopen("a.out","w",stdout);ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);cin>>n>>m;fill(in+1,in+1+n,n-1);for(int i=1,x,y;i<=m;i++){cin>>x>>y;in[x]--,in[y]--;q[x].push_back(y);q[y].push_back(x); }for(int i=1;i<=n;i++){f[i][1]=in[i];temp=(temp+f[i][1])%mod;}for(int i=1;i<=n;i++){f[i][2]=temp-f[i][1];for(int j=0;j<q[i].size();j++){f[i][2]-=f[q[i][j]][1];}ans=(ans+f[i][2])%mod;}temp=0; for(int i=1;i<=n;i++){f[i][3]=ans-f[i][2];for(int j=0;j<q[i].size();j++){f[i][3]-=f[q[i][j]][2];}temp=(temp+f[i][3])%mod;}
//	cout<<temp;sum=1ll*temp*temp%mod; ans=0;for(int i=1;i<=n;i++){ans=(ans+1ll*f[i][2]*in[i]%mod*in[i]%mod)%mod;}
//	cout<<ans;cout<<1ll*sum*ans%mod;return 0;
}
/*
4 1
1 2
*/

B. 铁路

新开一个数组来对应新建节点的位置,把位置指到合并的点中深度最小的点即可,这里合并时用并查集维护每个联通块

压缩路径也到深度最小的点,这样就对应起来了

点击查看代码
#include<bits/stdc++.h>
const int maxn=5e5+10;
using namespace std;
int head[maxn],nxt[maxn<<1],to[maxn<<1],tot;
int n,m,fa[maxn],last[maxn],pos[maxn<<1],size;
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void add(int x,int y)
{to[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
void addm(int x,int y)
{add(x,y),add(y,x);
}
int pre[maxn],deep[maxn],st[20][maxn],cnt;
struct Lca
{int get(int x,int y){return deep[x]<deep[y]?x:y;}void lsx(int x,int fa){pre[x]=++cnt,last[x]=fa,st[0][cnt]=fa;deep[x]=deep[fa]+1;for(int i=head[x];i;i=nxt[i]) if(to[i]!=fa) lsx(to[i],x);}void init(){lsx(1,0);for(int i=1;(1<<i)<=n;i++)for(int j=1;j<=n-(1<<i)+1;j++)st[i][j]=get(st[i-1][j],st[i-1][j+(1<<i-1)]);}int lca(int x,int y){if(x==y) return x;if((x=pre[x])>(y=pre[y])) swap(x,y);int l=__lg(y-x);return get(st[l][x+1],st[l][y-(1<<l)+1]);}
}e;void merge(int x,int y,int i)
{int p=e.lca(x,y);int a=find(x),b=find(y),c=find(p);
//	cout<<a<<" "<<b<<" "<<p<<endl; while(find(a)!=find(c)){a=fa[a]=find(last[a]);size--;}while(find(b)!=find(c)){
//		cout<<b<<" "<<last[b]<<"!"<<endl; b=fa[b]=find(last[b]);	size--;}pos[n+i]=c;
}int main()
{freopen("a.in","r",stdin);freopen("a.out","w",stdout);ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);cin>>n>>m;size=n;for(int i=1;i<=n;i++)fa[i]=i,pos[i]=i;for(int i=1;i<n;i++){int x,y;cin>>x>>y;addm(x,y);}e.init();for(int i=1;i<=m;i++){int x,y;cin>>x>>y;x=pos[x];y=pos[y];
//		cout<<x<<" "<<y<<"!"<<endl; merge(x,y,i);cout<<size<<'\n';	}return 0;
}
/*
10 5
2 1
9 7
4 10
1 8
3 4
1 7
3 2
6 1
1 51 6
8 4
5 12
13 13
9 14*/

C. 光纤

破防了,这东西谁愿意改谁改,我改不了一点。。。

找凸包的每一条边的高,找最小的那个就是答案

点击查看代码
#include<bits/stdc++.h>
#define int __int128
const int maxn=1e6+10;
using namespace std;
typedef pair<int,int>pr;
int n,top,st[maxn];
pr p[maxn];
bool used[maxn];template<typename T> inline T read() {T X = 0; bool flag = 1; char ch = getchar();while (ch < '0' || ch > '9') {if (ch == '-') flag = 0; ch = getchar();}while (ch >= '0' && ch <= '9') {X = (X << 1) + (X << 3) + ch - '0'; ch = getchar();}if (flag) return X;return ~ (X - 1);
}template<typename T> inline void write(T X) {if (X < 0) {putchar('-'); X = ~ (X - 1);}int s[50], top = 0;while (X) {s[++top] = X % 10; X /= 10;}if (!top) s[++top] = 0;while (top) putchar(s[top--] + '0');return;
}pr operator - (pr a,pr b)
{return {a.first-b.first,a.second-b.second};
}int cross(pr a,pr b,pr c)
{pr u,v;u=b-a,v=c-a;return u.first*v.second-v.first*u.second;
}pr s1(pr a,pr b,pr c)
{pr u,v;u=b-a,v=c-a;int x=(u.first*v.second-v.first*u.second);return {x*x,u.first*u.first+u.second*u.second};
}void pre()
{sort(p+1,p+n+1);for(int i=1;i<=n;i++){while(top>=2&&cross(p[st[top-1]],p[st[top]],p[i])>0){used[st[top]]=0;top--; }st[++top]=i;used[i]=1;}used[1]=0;for(int i=n-1;i>=1;i--){if(used[i])continue;while(top>=2&&cross(p[st[top-1]],p[st[top]],p[i])>0) top--;st[++top]=i;}
}pr yue(pr x)
{int a=x.first,b=x.second,c=__gcd(a,b);return {a/c,b/c};
}bool cmp(pr a,pr b)
{pr c={a.first*b.second,a.second*b.second};pr d={b.first*a.second,b.second*a.second};return c.first>d.first;
}pr min(pr a,pr b)
{if(!b.first) return a; return cmp(a,b)?b:a;
}void solve()
{pr a=p[st[1]],b=p[st[2]],c=p[st[3]];pr ans=s1(a,b,c);int k=3;for(int i=4;i<top;i++){pr d=s1(a,b,p[st[i]]);if(d.first>ans.first){ans=d;k=i;}}
//	write(ans.first); int x=2,y=3;pr l={0,1};for(int i=k,cnt=1;cnt<top-1;cnt++,x=(x+1)%top,y=(y+1)%top){if(!x)x++;if(!y)y++;while(1){a=p[st[x]],b=p[st[y]],c=p[st[i]];pr d=s1(a,b,c);d=yue(d),ans=yue(ans);if(cmp(d,l))l=d;else {i--;if(!i)i=top-1;break;}i=(i+1)%top;if(!i)i++;if(i+1==x||i+1==y) break; }
//		write(l.first); ans=min(ans,l);}
//	cout<<ans.first<<" "<<ans.second<<endl; ans={ans.first,ans.second*4};ans=yue(ans); write(ans.first);cout<<"/";write(ans.second);
}signed main()
{freopen("ex_A2.in","r",stdin);
//	freopen("a.out","w",stdout);
//	ios::sync_with_stdio(0);
//	cin.tie(0),cout.tie(0);n=read<int>();for(int i=1;i<=n;i++){int x,y;x=read<int>(),y=read<int>();p[i]={x,y};}pre(); solve();return 0;
}
/*
5
0 0
2 0
1 3
1 2
1 1
*/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/802639.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

读构建可扩展分布式系统:方法与实践13可扩展的事件驱动处理

可扩展的事件驱动处理1. 可扩展的事件驱动处理 1.1. 使用消息传递系统进行通信,你可以创建松耦合的架构1.1.1. 消息生产者只是将消息存储在队列中,而不用关心消费者如何处理消息1.1.2. 有一个或多个消费者,并且生产者和消费者的集合可以随着时间的推移而改变1.1.3. 有助于提…

java基础 -反射笔记

710,反射快速入门 代码: 先创建一个 re.properties 文件:classfullpath=com.hspedu.Cat method=hiCat.javapackage com.hspedu;public class Cat {private String name = "招财猫";public void hi() { //常用方法System.out.println("hi " + name);} …

全网最适合入门的面向对象编程教程:52 Python函数方法与接口-Protocol协议与接口

在Python中,协议(Protocol)和接口(Interface)是用于定义类和对象之间交互的一种方式,特别是在实现多态性和代码可重用性时,协议是一种抽象概念,描述了对象所需实现的方法和属性,而不关心具体的类或实现。全网最适合入门的面向对象编程教程:52 Python 函数方法与接口-…

机器学习第6次作业

机器学习作业6 学号:102102156 姓名:高涛 1. 朴素贝叶斯与KNN分类性能比较 1.1 代码1.2 绘制结果2.维数约简可视化 2.1 代码2.2 绘制结果3.1 降维前后分类精度比较 3.1 代码同上 3.2绘制结果

Docker 部署 vue 项目

概述 技术栈:docker + vue + nginx 1、docker下载安装 nginx docker pull nginx2、创建nginx挂载目录 /usr/local/nginx (可根据自己需要存放文件的位置自行创建目录) mkdir -p /usr/local/nginx3、vim 创建default.conf server {listen 80;server_name localhost;#c…

TCP协议三次握手的个人理解

TCP协议的核心是可靠的数据传输,而保证传输是可靠的那就要求客户端和服务端双方都具备正常的收发功能。 基于此,第一次握手的时候,当服务端接收到这个SYN请求时,表明客户端要进行TCP连接,同步序列号seq=x,那么从服务端的角度来看: 1、客户端的发送能力是正常的; 服务端…

[vulnhub]LAMPSecurity: CTF5

https://www.vulnhub.com/entry/lampsecurity-ctf5,84/主机发现端口扫描探测存活主机,139为靶机 nmap -sP 192.168.75.0/24 Starting Nmap 7.93 ( https://nmap.org ) at 2024-09-23 17:27 CST Nmap scan report for 192.168.75.1 Host is up (0.00049s latency). MAC Address…

jni安全利用的简单学习

首先定义一个最简单的类 public class EvilClass {public static native String execCmd(String cmd); } 因为我是MacOs端,在当前目录执行 javac EvilClass.java javac -h . EvilClass.java 生成 EvilClass.h 文件 /* DO NOT EDIT THIS FILE - it is machine generated */ #i…

day6[Llamaindex RAG实践]

"xtuner是什么?"在使用 LlamaIndex 之前InternLM2-Chat-1.8B模型不会回答借助 LlamaIndex 后 InternLM2-Chat-1.8B 模型具备回答的能力

【专题】2024AI智慧生活白皮书:AI智能科技重塑居家体验报告合集PDF分享(附原数据表)

原文链接:https://tecdat.cn/?p=37748 AI 已然成为家电家居市场的创新核心动力,可在个性化识别、预测维护等多方面提升产品价值。家享生活行业智能化展现多元场景,清洁智能崛起超厨房智能居第二,全屋智能潜力巨大。“套装 / 集成智能” 等品类增长快,智能新客多由老客升级…

kettle从入门到精通 第八十七课 ETL之kettle kettle文件上传

1、kettle本身文件上传功能不是很友好,甚至是不能直接使用,需要调整文件上传接口才可以正常接收到文件,本次讲解内容主要是通过自定义插件解决这个问题。 2、通过springboot 编写简单demo,模拟文件上传,接口支持三个参数unitCode、password、和文件dataFile。 java代码如下…