首页 > 其他分享 >CSP-S模拟14

CSP-S模拟14

时间:2022-10-04 21:46:51浏览次数:54  
标签:tem int ll long mx seg CSP 模拟 14

T1.
考场:这不就单峰函数吗?我会
3min后:这函数有相等区间啊!爬山
3h后:woc这题写了3小时!赶紧去冲后几题暴力
不过最后还是A了





%:pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const int N = 3e5+10;
struct seg_s{
	int l, r;
}seg[N];
typedef unsigned long long ull;
mt19937 rd = mt19937(1919810);
typedef long long ll;
int rr(int l, int r){
	uniform_int_distribution <> d(l, r);
	return d(rd);
}
int calc(const seg_s& x, int y){
	if(y > x.r) return x.r;
	if(y < x.l) return x.l;
	else return y;
}
int n;
int tot;
ll a[N];
ll get_ans(int mid){
	ll ret = 0;
	ll rsum = 0;
	for(int i = 1; i <= n; ++i){
		a[i] = calc(seg[i], mid);
	}
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= n; ++i){
		rsum += a[i];
	}
	for(int i = 1; i <= n; ++i){
		rsum -= a[i];
		ret += rsum - a[i] * (n - i);
	}
	++tot;
	return ret;
}
ll get_dt(int mid){	
	ll ret = 0;
	ll rsum = 0;
	for(int i = 1; i <= n; ++i){
		a[i] = calc(seg[i], mid);
	}
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= n; ++i){
		rsum += a[i];
	}
	for(int i = 1; i <= n; ++i){
		rsum -= a[i];
		ret += a[i] - mid;
	}
	++tot;
	return ret;
}
ld S = 50, dt = 0.85, T = 0.001, Div = 1e4;
int mx = 0, mn;
int x;
ll Ans = 1e18;
void SimulateAnnel(){
	ld tem = S;
	while(tem > T){
		int dx = rr(floor(-tem / Div * mx), ceil(tem/Div * mx));
		// cerr<<"tem = "<<tem << "range = " << (ceil(tem/Div * mx) - floor(-tem / Div * mx)) << "x = " << x << endl;
		if(x + dx > mx || x + dx < 0) continue;
		ll nans = get_ans(x + dx);
		if(nans < Ans){
			x += dx, Ans = nans;
		}
		if(n > 1e4){
			if(tem > 1) {
				tem *= 0.7;
			}else if(tem < 0.01){
				tem *= 0.65;
			}else{
				tem *= 0.85;
			}
		}else{
			tem *= dt;
		}
	}
	for(int i = -2; i < 0; ++i){
		Ans = min(Ans, get_ans(x + i));
	}
	for(int i = 1; i <= 2; ++i){
		Ans = min(Ans, get_ans(x + i));
	}
}
int read(){
	int x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	do{x = x * 10 + ch -'0', ch = getchar();}while(isdigit(ch));
	return x;
}
int main(){
	// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	// cin >> n;
	n = read();
	if(n <= 1e4){
		S = 1E4, dt = 0.92, T = 0.01;
	}
	for(int i = 1; i <= n; ++i){
		// cin >> seg[i].l >> seg[i].r;
		seg[i].l = read(), seg[i].r = read();
		mx = max(mx, seg[i].r);
		mn = min(mn, seg[i].l);
	}
	int l = mn, r = mx, res = (mx + mn) / 2;
	while(r - l > 3e3){
		int mid = (l + r) >> 1;
		if(get_dt(mid) <= 0){
			res = mid;
			r = mid - 1;
		}else{
			l = mid + 1;
		}
	}
	x = res;
	// x = (mx + mn)/ 2;
	int cnt = 1;
	SimulateAnnel();	
	// cerr<<"rawx " << res << endl;
	// cerr<<"x = " << x << endl;
	// cerr<<"tot = " << tot << endl;
	// cerr<<"dtx = " << x - res << "val = "<<1.0 * (x - res)/mx << endl;
	// printf("%lld", ans);
	cout << Ans << endl;
	// cout << fixed<< setprecision(0) << round(Ans) << endl;
	return 0;
}

标签:tem,int,ll,long,mx,seg,CSP,模拟,14
From: https://www.cnblogs.com/cdsidi/p/16743665.html

相关文章

  • AtCoder Regular Contest 149
    A发现所有数字都相同的数一共只有\(10^6\)种,考虑枚举每种情况,关键在于如何判断一个数\(\bmodm\)是否为\(0\)。考虑\(9\bmod8=1\),而\(99\bmod8=(9\times10+9)\b......
  • pydantic学习与使用-14.exclude_unset去掉未传值的字段
    前言使用pydantic定义数据模型,有些非必填的字段,我们希望在实例化时未传值的字段去掉,这样可以取值一些为None的字段。遇到问题age和address是非必填字段classUser......
  • 【C语言_14】快速学会使用字符数组
    1.初始化字符数组#include<stdio.h>intmain(){charstr[20]="helloworld";//charstr[20]={'h','e','l','l','o','w','o','r','l','d'};printf("......
  • 安装Docker容器时,出现https://yum.dockerproject.org/repo/main/centos/7/repodata/re
    解决办法:首先确定把相应的前置包都安装好,之后操作命令行:执行yum-config-manager--disabledockerrepo命令然后再执行:sudo yum installdocker-cedocker-ce-clicont......
  • [挑战记录]模拟/搜索题单
    2022100320:18[省选联考2022]预处理器\(\operatorname{string}\)科技题#include<cstdio>#include<cstring>#include<string>#include<iostream>#include<map>#de......
  • OFF14
    由小至大推导公式,从2段开始一直到n段intcuttingRope(intn){//dp[i-j]*j分为多段//i-j*j分为俩端intdp[n+1];memset(dp,0,sizeof(dp));dp......
  • 「CF1455G」Forbidden Value 题解 (DP,线段树合并)
    题目简介已知初始值\(x=0\),给定下面\(2\)种命令:set\(y\)\(v\),令\(x=y\),或花费\(v\)元钱删除该命令;if\(y\)...end,如果\(x==y\),执行if...end中的命令,否则跳......
  • 25-70K*14薪| 梅卡曼德视觉算法、C++软件开发工程师等职位招聘
    3D视觉工坊致力于推荐最棒的工作机会,精准地为其找到最佳求职者,做连接优质企业和优质人才的桥梁。高级C++软件开发工程师薪水:25K-60K*14薪岗位职责:1、负责相关软件系统(客户端)的设......
  • Cisco模拟器使用教程
    一、使用三层交换机实现跨VLAN间的通信1.vlan配置如图所示局域网,要将不同的PC机配置到不同的vlan下。在二层交换机的配置模式(即Switch(config)#)下:这里配置的端口是与P......
  • 43rd 2022/10/4 模拟赛总结30
    这次还行?rank5,其实也不是多高不可攀,就是认真打,暑假时就上过前五好多次其实比赛历程也很简单第一题很忽悠,思路乱的一批,但是这次冷静下来把思路理清就切了很简单的概率D......