1. 程式人生 > >【CF套題】Good Bye 2018

【CF套題】Good Bye 2018

【前言】
自閉了,四題以後就看著排名一直往下掉。
E想了個線段樹維護階梯,沒看wiki,出來才發現是公式題。
F想了個凸包,結果是個貪心。
心態炸裂(然而rk500還能漲分)

【題目】
原題地址

A.New Year and the Christmas Ornament

瞎搞。

#include<bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii; const int INF=0x3f3f3f3f; int a,b,c,t; int read() { int ret=0,f=1;char c=getchar(); while(!isdigit(c)) {if(c=='-')f=0;c=getchar();} while(isdigit(c)) ret=ret*10+(c^48),c=getchar(); return f?ret:-ret; } int main() { #ifndef ONLINE_JUDGE freopen("A.in","r",stdin); freopen
("A.out","w",stdout); #endif a=read();b=read();c=read(); t=min(a+2,b+1);t=min(t,c); if(t<0) t=0; printf("%d\n",t+t+t-3); return 0; }

B.New Year and the Treasure Geolocation

排序後首尾相加即可。

#include<bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std; typedef long long ll; typedef pair<int,int> pii; const int INF=0x3f3f3f3f,N=1005; int n; pii a[N],b[N]; int read() { int ret=0,f=1;char c=getchar(); while(!isdigit(c)) {if(c=='-')f=0;c=getchar();} while(isdigit(c)) ret=ret*10+(c^48),c=getchar(); return f?ret:-ret; } int main() { #ifndef ONLINE_JUDGE freopen("B.in","r",stdin); freopen("B.out","w",stdout); #endif n=read(); for(int i=1;i<=n;++i) a[i].fi=read(),a[i].se=read(); for(int i=1;i<=n;++i) b[i].fi=read(),b[i].se=read(); sort(a+1,a+n+1);sort(b+1,b+n+1); printf("%d %d\n",a[1].fi+b[n].fi,a[1].se+b[n].se); return 0; }

C.New Year and the Sphere Transmission

列舉 n n 的所有約數,等差數列求和後去重即可。

#include<bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f,N=1e6+10;
int n,cnt;
ll a[N];

int read()
{
	int ret=0,f=1;char c=getchar();
	while(!isdigit(c)) {if(c=='-')f=0;c=getchar();}
	while(isdigit(c)) ret=ret*10+(c^48),c=getchar();
	return f?ret:-ret;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("C.in","r",stdin);
	freopen("C.out","w",stdout);
#endif
	n=read();
	for(int i=1,j;(ll)i*i<=n;++i)
	{
		if(n%i) continue;
		a[++cnt]=(ll)(1+n-i+1)*(n/i)/2;
		if(i*i!=n) j=n/i,a[++cnt]=(ll)(1+n-j+1)*(n/j)/2;
	}
	sort(a+1,a+cnt+1);
	for(int i=1;i<=cnt;++i) if(a[i]!=a[i-1]) printf("%lld ",a[i]);

	return 0;
}

D.New Year and the Permutation Concatenation

考慮列舉將去掉多長的字首後後面的排列恰好補充前面的,則答案是 n n ! k = 1 n 1 n ! k ! n \cdot n! - \sum_{k=1}^{n-1} \frac{n!}{k!}

#include<bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f,mod=998244353;
const int N=1e6+10;
ll n,ans,fac[N];

int read()
{
	int ret=0,f=1;char c=getchar();
	while(!isdigit(c)) {if(c=='-')f=0;c=getchar();}
	while(isdigit(c)) ret=ret*10+(c^48),c=getchar();
	return f?ret:-ret;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	n=read();
	fac[0]=1;for(int i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod;
	ll t=1;
	for(int i=1;i<n;++i) 
	{
		t=t*(n-i+1)%mod;
		ans=(ans+(ll)t*(fac[n-i]-1)%mod)%mod;
	}
	ans=(ans+fac[n])%mod;
	printf("%lld\n",(ans%mod+mod)%mod);
	return 0;
}

E.New Year and the Acquaintance Estimation

Erdős–Gallai theorem
結論是對於一個從大到小排序後的度數序列 d d ,能構成簡單圖當且僅當:
i = 1 k d i ( k ( k 1 ) + j = k + 1 n min ( d j + k ) ) \sum_{i=1}^k d_i\leq (k(k-1)+\sum_{j=k+1}^n \min(d_j+k)) 對於 1 k n 1\leq k\leq n 均成立。
答案顯然是一個公差為 2 2 的等差序列,我們二分答案的上下界,上述式子不成立時,若第 n + 1 n+1 個點已滿足條件,說明答案太大,否則說明答案太小。

#include<bits/stdc++.h>
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f,N=1e6+10;
int n;
ll a[N],b[N],s[N];

int read()
{
	int ret=0,f=1;char c=getchar();
	while(!isdigit(c)) {if(c=='-')f=0;c=getchar();}
	while(isdigit(c)) ret=ret*10+(c^48),c=getchar();
	return f?ret:-ret;
}

void solve()
{
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i) s[i]=s[i-1]+a[i];
	for(int i=1,j=1;i<=n;++i)
	{
		ll l=s[n]-s[n-i],r=(ll)i*(i-1);
		while(j<=n && a[j]<i) ++j;
		r+=s[min(j-1,n-i)]+(ll)max(0,n-i-j+1)*i;
		ll now=a[n-i+1],tmp=l-r;
		if(tmp<=i && tmp<=now) ++b[max(tmp,0ll)],--b[now+1];
		l-=a[n-i+1];r+=min(a[n-i+1],(ll)i);
		tmp=r-l;
		if(tmp>=now+1) ++b[now+
            
           

相關推薦

CFGood Bye 2018

【前言】 自閉了,四題以後就看著排名一直往下掉。 E想了個線段樹維護階梯,沒看wiki,出來才發現是公式題。 F想了個凸包,結果是個貪心。 心態炸裂(然而rk500還能漲分) 【題目】 原題地址 A.New Year and the Christmas Ornament 瞎搞

CFCodeforces Round #524 (Div. 2) (1080A~F)

原題地址 迴歸 CF \text {CF} CF,這場堪堪上紫。 A.Petya and Origa

CF Gym101623 NWERC2017

【前言】 在BZOJ上翻題看到了幾題,心血來潮就全寫了。 C這個搜尋我不是很會寫,直接看了別人的(然而還是沒寫) 然後這個J讓我知道一定不能在還要用值的時候刪掉一個指標。 【題目】 原題地址 A.Ascending Photo 單獨寫。 B.Boss Battle 顯

CFEducational Codeforces Round 57

【前言】 打了小號,做到心態爆炸,雖然最後過了6T。 然而十分後悔為什麼沒有用大號打,大號打就上橙了qwq。 【題目】 原題地址 A.Find Divisible 輸出 l

CFCodeforces Round #528 (Div. 1)

【前言】 並不能打div2的我十分絕望。 雖然上分了還是很高興。 【題目】 原題地址 A.Connect Three 將三個格子按 x

BZOJ 5248 [2018多省省隊聯測]一雙木棋

har def temp zoj its typename 技術分享 max 就是 Description 菲菲和牛牛在一塊n行m列的棋盤上下棋,菲菲執黑棋先手,牛牛執白棋後手。棋局開始時,棋盤上沒有任何棋子, 兩人輪流在格子上落子,直到填滿棋盤時結束。落子的規則是:一個格

BZOJ 5249 [2018多省省隊聯測]IIIDX

sort 技術分享 會有 bzoj NPU 他在 若有 nan shu Description 【題目背景】 Osu聽過沒?那是Konano最喜歡的一款音樂遊戲,而他的夢想就是有一天自己也能做個獨特酷炫的音樂遊戲。現在,他在世界知名遊戲公司KONMAI內工作,離他的夢想也越

Codeforces#321 div2

A - Kefa and First Steps 簡單dp /* ********************************************** File Name: a

2015ACM/ICPC亞洲區長春站 HDU5532 5533 5534 5536 5538

水幾個題,熟悉一下鍵盤。。。 HDU5532AlmostSortedArray 題意:ASA定義為,僅去掉一個(OneandOnlyOne)元素後陣列是非降序或者非升序。 題解:很明顯,判斷一個序列是否有序可以通過判斷其LongestNonDecreasing

GDOI模擬雨天的尾巴

每次 ctu inner table 樹套樹 ner acc 整數 nbsp 雨天的尾巴 深繪裏一直很討厭雨天。灼熱的天氣穿透了前半個夏天,後來一場大雨和隨之而來的洪水,澆滅了一切。雖然深繪裏家鄉的小村落對洪水有著頑固的抵抗力,但也倒了幾座老房子,幾棵老樹被連根拔起

基礎水統計單詞個數

int pan 一個 else art 個數 print urn 是不是 1 //1.統計單詞的個數 2 #include <stdio.h> 3 int main(void) 4 { 5 int i, flag = 0, number =

LeetCode刷SQL-Combine Two Tables

介紹 左關聯查詢 col 每一個 cit http sid combine sql查詢 Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ |

練習賽補poj 3026 Borg Maze bfs+最小生成樹坑~

lec pro 起點 live tin put gets work cond Description The Borg is an immensely powerful race of enhanced humanoids from the delta quadrant

編程下廚房

main 下廚房 包含 ins size out 測試 text 表示 【編程題】下廚房 題目描述   牛牛想嘗試一些新的料理,每個料理需要一些不同的材料,問完成所有的料理需要準備多少種不同的材料。 輸入描述:   每個輸入包含 1 個測試用例。每個測試用例的第 i 行,表

2017 ACM-ICPC 亞洲區(西安賽區)網絡賽C. Sum腦洞

整數 namespace pac line main expr esp for cnblogs 限制:1000ms 32768K Define the function S(x) for xx is a positive integer. S(x) equals to t

BZOJ3629-聰明的燕姿數學雜

cee left weibo sina iuc info ndt www. style T浪h改姆9少FVT優樂Phttp://www.docin.com/vwhd00606 AM0瓤XN7Ukahttp://weibo.com/u/6367436044 蹈4s釉畏耐E

編程不引入第三個變量,而交換兩個變量的值

其中 blog b+ 沒有 來源 article else 位移 text 不引入第三個變量,而交換兩個變量的值 方法一:算術運算 1 int a,b; 2 a=10;b=12; 3 a=b-a; //a=2;b=12 4 b=b-a; //a=2;b=10

UOJ #30. CF Round #278Tourists

每天 需要 del 每次 class 有一個 stdout markdown math Description Cyberland 有 n 座城市,編號從 1 到 n,有 m 條雙向道路連接這些城市。第 j 條路連接城市 aj 和 bj。每天,都有成千上萬的遊客來到 Cyb

不吹不擂,你想要的Python面試都在這裏了315+道

def 每天 leet soup XML unique 通信 cors 後進先出 https://www.cnblogs.com/wupeiqi/p/9078770.html 近日恰逢學生畢業季,課程後期大家“期待+苦逼”的時刻莫過於每天早上內容回顧和面試題問答部分【臨

樹狀數組主席樹

void c++ 查詢 %d 就是 font clu log 第一次   這是你顧第一次寫【樹套樹】!!!!!!!!   【原題】   求區間第k小元素,區間可修改   【正解】   如果沒有修改的話,就直接寫搞個主席樹利用前綴和加加減減一下就好了。但是多了個修改,修改以為