首页 > 其他分享 >CodeForces 852C Property

CodeForces 852C Property

时间:2023-11-10 13:55:06浏览次数:40  
标签:typedef 852C bmod CodeForces long int maxn Property define

洛谷传送门

CF 传送门

NOIP 模拟赛 T1,小清新几何题。

要让选出的点组成的多边形面积最大,就要让正多边形的面积减去选出的点组成的多边形面积最小。而这个面积差可以表示成 \(2n\) 个三角形的面积,即 \(\sum\limits_{i = 0}^{2n - 1} S_{\triangle A_i A_{(i + 1) \bmod n} B_{(i + 1) \bmod n}}\)。

众所周知 \(S_{\triangle} = \frac{1}{2} ab \sin \theta\),而在本题中 \(\theta\) 恒等于正 \(2n\) 多边形的内角,因此可以约去。如果令给出的排列为 \(p\),要求的排列为 \(q\),相当于最小化 \(\sum\limits_{i = 0}^{n - 1} (n - p_i) q_i + (n - q_i) p_{(i + 1) \bmod n}\)。化简后相当于最大化 \(\sum\limits_{i = 0}^{n - 1} q_i (p_i + p_{(i + 1) \bmod n})\)。

令 \(c_i = p_i + p_{(i + 1) \bmod n}\),式子变成 \(\sum\limits_{i = 0}^{n - 1} q_i c_i\)。显然小的和小的配对,大的和大的配对,因此 \(q_i\) 即为 \(c_i\) 的排名。排序求一下即可。

code
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

const int maxn = 200100;

int n, a[maxn], b[maxn], c[maxn], d[maxn];

void solve() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		b[i] = i;
	}
	for (int i = 0; i < n; ++i) {
		d[i] = a[i] + a[(i + 1) % n];
	}
	sort(b, b + n, [&](const int &x, const int &y) {
		return d[x] < d[y] || (d[x] == d[y] && x < y);
	});
	for (int i = 0; i < n; ++i) {
		c[b[i]] = i;
	}
	for (int i = 0; i < n; ++i) {
		printf("%d ", c[i]);
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

标签:typedef,852C,bmod,CodeForces,long,int,maxn,Property,define
From: https://www.cnblogs.com/zltzlt-blog/p/17823922.html

相关文章

  • spring复习:(57)PropertyOverrideConfigurer用法及工作原理
    一、属性配置文件dataSource.url=jdbc:mysql://xxx.xxx.xxx.xxx/testdataSource.username=rootdataSource.password=xxxxxxdataSource.driverClassName=com.mysql.jdbc.Driver#dataSource.type=com.alibaba.druid.pool.DruidDataSource二、spring配置文件<?xmlversion="1.0&quo......
  • Spring复习:(56)PropertySourcePlaceholderConfigurer的工作原理
    PropertySourcePlaceholderConfigurer的用途:通过配置文件(比如.properties文件)给bean设置属性,替代属性占位符示例:属性配置文件spring.datasource.url=jdbc:mysql://xxx.xxx.xxx.xxx/testspring.datasource.username=rootspring.datasource.password=xxxxxxspring.datasource.dri......
  • Educational Codeforces Round 126 (Rated for Div. 2)
    https://codeforces.com/contest/1661/B题数据很小,直接bfs预处理就行C题随便猜了一下,设mx=\(max\{a_i\}\)最后的值应该是mx,mx+1,mx+2,mx+3之类的吧D题刚开始从前面考虑,陷入僵局,一度非常的困,学习凯库勒睡了一会,就突然想到了,前面不行,就从后面考虑,可以发现,从后面考虑的话,就非常......
  • Uncaught TypeError: Cannot read property ‘addEventListener‘ of null 求助!!!!!!
    今天在项目中遇到个问题如下:vue项目中public的index.html文件script标签引入了一个外部的js文件,里面有一个方法每次调用的时候都会报错UncaughtTypeError:Cannotreadproperty‘addEventListener‘ofnull,网上查的所有办法都试过了:跟标签摆放先后位置,放到onload方法中都没......
  • Codeforces Round 908 (Div. 2)
    A.SecretSport题意:A与B选手在下棋,规定下赢X把看作赢一局,一共赢Y把的那个是最后的赢家。思路:因为不知道x,y到底是多少,n的范围是到20,所以只需要枚举x即可,时间复杂度不高,注意的是,如果枚举结果是A赢,那么给定字符串的最后一个值一定是A,反之也是。#include<bits/stdc++.h>usingnam......
  • Codeforces Visit
    CodeforcesVisit记录一下自己大概vis了那几场??随机补题大法好!CF632Div.2飞速模拟出ABC。优势在我!CF1333D发现就是把字符串变成LLRR此类形状。所以开头必然是L啊,然后我们考虑先把L换到第一个。发现必然是LLLLLLLLLLLRRRRRRRR啊,很快啊,不会了。CF1333E你妈妈con......
  • INotifyPropertyChanged
      可以将TextBox控件(其他控件也基本一样)与某个变量进行绑定,做出改变变量则控件也跟着改变的效果。  首先需要声明一个类,该类用来与控件绑定:usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Runtime.CompilerServices;namespaceTestWPF{......
  • Educational Codeforces Round 157 (Rated for Div. 2)
    A.TreasureChest题目大意:人在0处,宝藏在x,钥匙在y,人最多拿宝箱z秒,问你最快多久开宝箱?思路:如果说钥匙在宝箱的左边,那么人只需要往右走就是最佳答案,如果钥匙在宝箱的右边,那么人只需要拿的宝箱到最佳地点就行#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ intx,y......
  • Educational Codeforces Round 157 (Rated for Div. 2)
    F.FancyArrays第一眼感觉是去容斥掉条件1,因为条件2其实挺紧的。不妨用\(f(l,r)\)表示\(a\)值域在\([l,r]\)的方案(满足条件2)。那么答案为\(f(0,+\infty)-f(0,x-1)-f(x+k,+\infty)\),因为如果选了\([0,x-1]\)的数,那么还要更大的话,一定会选到\([x,x+k-1]\),所以你要......
  • Codeforces Round 907 (Div. 2)
    ASortingwithTwos题目大意:选择一个m,然后将1~2^m下表的数减一,可以操作无限次,问你能不能使数组单调递增题目数据851234556534496557566874432162245328131719275717913531757179921012340678910YESYESYE......