首页 > 其他分享 >csp-s模拟12

csp-s模拟12

时间:2024-10-18 17:24:17浏览次数:1  
标签:12 int long vis freopen using csp 模拟 define

又双叒叕垫底啦!!!

rank 22,T1 0,T2 20,T3 0,T4 30。

逆天模拟赛,逆天题面,怕你赛场上不会打暴力真是煞费苦心出了一场暴力专场。

小h的几何

高斯消元求圆心精度被卡炸了,乐了。咋还考向量啊,不学文化课,输了。

九点圆的圆心是外心\(O\)和垂心\(H\)的中点,且\(\overrightarrow{OH}=\overrightarrow{OA}+\overrightarrow{OB}+\overrightarrow{OC}\),因为\(O\)为原点,所以\(\Omega(A,B,C)=\frac{A+B+C}{2}\)。

证明的话不好写,机房没有条件,画图太难受的。可以百度一下。

用到向量的相关知识,文化课好题。

upd:发现有大佬写了,挂一下。come from DrRatio

点此查看代码
#include<bits/stdc++.h>
#include<bits/extc++.h>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;
#define rep(i,s,t,p) for(int i = s;i <= t; i += p)
#define drep(i,s,t,p) for(int i = s;i >= t; i -= p)
#define Infile(x) freopen(#x".in","r",stdin)
#define Outfile(x) freopen(#x".out","w",stdout)
#define Ansfile(x) freopen(#x".ans","w",stdout)
#define Errfile(x) freopen(#x".err","w",stderr)
#ifdef LOCAL
    FILE *InFile = Infile(in),*OutFile = Outfile(out);
    FILE *ErrFile = Errfile(err);
#else
    FILE *InFile = Infile(geometry),*OutFile = Outfile(geometry);
#endif
using ll=long long;using ull=unsigned long long;
using db = double;using ldb = long double;
const int N = 5e5 + 10;
const ldb pi = 3.1415926535897932384626;
struct node{ldb x,y;}p[N];
int n,ct[N];
ldb res,ansx,ansy;
inline void solve(){
    cin>>n;
    res = 3.0/n/(n-1)/(n-2);
    rep(i,1,n,1){
        int q;cin>>q;
        ldb ct = 1.0*q/1e9*pi;
        p[i].x = cos(ct),p[i].y = sin(ct);
    }
    ldb ansx = 0,ansy = 0;
    ll tot = 1ll*(n-1)*(n-2)/2;
    rep(i,1,n,1){
        ansx += tot*p[i].x*res;
        ansy += tot*p[i].y*res;
    }
    cout<<fixed<<setprecision(16)<<ansx<<' '<<ansy<<'\n';
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

小w的代数

想等学了圆方树以后去打\(O(n^2)\)的做法,仙姑了。

小y的数论

难题。

膜拜已经要切了。

小j的组合

简单题,没场切挺遗憾的。

考虑求出树的直径以后,答案\(g=n-|树的直径|\)。

证明的话,考虑贪心一下,跑dfs,如果要走哈密顿路的话最后肯定是一条链。

考虑到如果要让新增的节点数最少的话肯定要让dfs回溯所经过边的最少,那么肯定是除了树的直径以外的其余边回溯,直接求树的直径即可。

然后求树的直径,暴力建边,dfs求哈密顿路,注意直径上的点要最后走。

时间复杂度\(O(n+m)\)

点此查看代码
#include<bits/stdc++.h>
#include<bits/extc++.h>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;
#define rep(i,s,t,p) for(int i = s;i <= t; i += p)
#define drep(i,s,t,p) for(int i = s;i >= t; i -= p)
#define Infile(x) freopen(#x".in","r",stdin)
#define Outfile(x) freopen(#x".out","w",stdout)
#define Ansfile(x) freopen(#x".ans","w",stdout)
#define Errfile(x) freopen(#x".err","w",stderr)
#ifdef LOCAL
    FILE *InFile = Infile(in),*OutFile = Outfile(out);
    // FILE *ErrFile = Errfile(err);
#else
    FILE *InFile = Infile(combo),*OutFile = Outfile(combo);
#endif
using ll=long long;using ull=unsigned long long;
using db = double;using ldb = long double;
#define eb emplace_back
const int N = 210;
vector<int> e[N];
int n,s,t,dep[N],fa[N],siz[N],son[N],ed[N],bf[N];
bitset<N> vis,flag;
inline int bfs(int s){
    queue<int> q;q.push(s);
    rep(i,1,n,1) dep[i] = bf[i] = 0;
    vis.reset();bf[s] = 0;dep[s] = 1;
    int mxdep = 0,far = s;
    while(q.size()){
        int x = q.front();q.pop();vis[x] = true;
        for(int y:e[x]){
            if(vis[y]) continue;
            dep[y] = dep[x] + 1;
            if(dep[y] > mxdep){mxdep = dep[y],far = y;}
            bf[y] = x;
            q.push(y);
        }
    }
    return far;
}
vector<int> ans;
inline void Bfs(int x){
    queue<int> q;q.push(x);
    while(q.size()){
        int x = q.front();q.pop();vis[x] = true;
        for(int y:e[x]){
            if(flag[y] || vis[y]) continue;
            q.push(y);ans.eb(x);
        }
    }
}
vector<int> out;
void dfs(int x,int f){
    out.eb(x);
    vis[x] = true;
    int to = 0;
    for(int y:e[x]){
        if(vis[y]) continue;
        if(flag[y]){to = y;continue;}
        dfs(y,x);
    }
    if(to && !vis[to]) dfs(to,x);
}
inline void solve(){
    cin>>n;rep(i,1,n-1,1){int u,v;cin>>u>>v;e[u].eb(v),e[v].eb(u);}
    s = bfs(t = bfs(1));
    int x = s;vis.reset();
    do{flag.set(x),x = bf[x];}while(x);
    rep(i,1,n,1) if(flag[i]) Bfs(i);
    int now = n+1;
    for(auto x:ans){
        for(int y:e[x]) e[y].eb(now),e[now].eb(y);
        now++;
    }now--;
    vis.reset();dfs(s,0);
    cout<<ans.size()<<'\n';
    for(auto i:ans) cout<<i<<' ';
    cout<<'\n';
    for(auto i:out) cout<<i<<' ';
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

标签:12,int,long,vis,freopen,using,csp,模拟,define
From: https://www.cnblogs.com/hzoi-Cu/p/18474674

相关文章

  • P5690 [CSP-S2019 江西] 日期 &&P7909 [CSP-J 2021] 分糖果 &&P5657 [CSP-S2019] 格雷
    今天继续懒惰,继续三合一!!![CSP-S2019江西]日期题目背景CSP-SJX2019T1题目描述Alice在纸上写下了一个日期,形式为\(\text{MM-DD}\),其中\(\text{MM}\)与\(\text{DD}\)都是两位数字,分别表示月和天,然而这个日期并不一定存在。Alice找来了Bob要他更改若干位上的数字,使得这个......
  • 基于Java微信小程序的模拟考试系统(源码+lw+部署文档+讲解等)
    项目运行截图技术框架后端采用SpringBoot框架SpringBoot是一个用于快速开发基于Spring框架的应用程序的开源框架。它采用约定大于配置的理念,提供了一套默认的配置,让开发者可以更专注于业务逻辑而不是配置文件。SpringBoot通过自动化配置和约定大于......
  • CSP-J模拟赛day6——试题
    全人杯奖金Description万人瞩目的第一届“全人杯”思维挑战赛正在紧锣密鼓的进行中,比赛的类别包括数学、物理和信息。为了激励同学们踊跃参与,比赛设置了一系列的奖项。对于每个学科,分别设置了一、二、三等奖以及鼓励奖和参与奖。其中,一等奖预设x名,奖金a元,二等奖预设y名,奖......
  • NOIP 模拟赛:2024-10-17
    挂分100pts。T1:数组不清空导致的。题意:\(n\)个物品,第\(i\)个物品花费\(2^{a_i}\),价值\(b_i\)。问获得\(k\)的价值最少花多少钱。\(n\le10^5\)。二分,求\(x\)块能买到多少价值。按花费从小到大枚举\(i=0\sim30\),维护一个"当前物品集合"\(q\),初始只存储\(a=0\)的......
  • 实时数据化可视化工具LightningChart .NET v12.1.1全新发布
    LightningChart.NET完全由GPU加速,并且性能经过优化,可用于实时显示海量数据-超过10亿个数据点。LightningChart包括广泛的2D,高级3D,Polar,Smith,3D饼/甜甜圈,地理地图和GIS图表以及适用于科学,工程,医学,航空,贸易,能源和其他领域的体绘制功能。立即获取LightningChart.NETv12.1.1正......
  • UVA1240 ICPC Team Strategy 做题记录
    看到\(n\le12\),考虑搜索。但是过不去,于是加上记忆化搜索即可。因为\(n\)不大,选了什么题可以状压进一个数里面。注意如果你在搜索的时候不判是否满足时间,那么你在dfs函数开头判断超时应该返回\(-1\)及以下。剩下的按照题意模拟即可。点击查看代码intn,a[4][maxn];i......
  • 闯关leetcode——112. Path Sum
    大纲题目地址内容解题代码地址题目地址https://github.com/f304646673/leetcode/tree/main/112-Path-Sum内容GiventherootofabinarytreeandanintegertargetSum,returntrueifthetreehasaroot-to-leafpathsuchthataddingupallthevalues......
  • 闯关leetcode——121. Best Time to Buy and Sell Stock
    大纲题目地址内容解题代码地址题目地址https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/内容Youaregivenanarraypriceswhereprices[i]isthepriceofagivenstockontheithday.Youwanttomaximizeyourprofitby......
  • 从早起到上班:用Java代码模拟你的日常生活
    现在我们把Java基本语法的知识串起来,通过一个有趣的小例子来模拟你从早起到上班的日常过程。这会用到变量、条件语句、循环语句等基本概念,来让你直观感受到Java是如何工作的。场景:从早上闹钟响起到你走进办公室假设你每天早上都会经历以下几个步骤:闹钟响了,起床。看看外面......
  • KubeSphere v4 全解析:揭秘您最关心的 12 大热点问题
    为了助力大家更顺畅地使用KubeSpherev4,我们精心汇总了十二个开发者高频关注的热点问题,这些问题全面覆盖了功能特性、性能表现、兼容性考量、安全保障以及升级流程等关键方面。接下来,我们将为大家逐一解答。KubeSpherev4涵盖了KubeSphere4.1.1和KubeSphere4.1.2。1.环......