1. 程式人生 > >【CF套題】Educational Codeforces Round 57

【CF套題】Educational Codeforces Round 57

【前言】
打了小號,做到心態爆炸,雖然最後過了6T。
然而十分後悔為什麼沒有用大號打,大號打就上橙了qwq。

【題目】
原題地址

A.Find Divisible

輸出 l l 2 l 2l

即可。

#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 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 int T=read(); while(T--) { int l=read(),r=read(); printf("%d %d\n",l,l*2); } return 0; }

B.Substring Removal

先找出前後相同字元能擴充套件到的位置,然後根據首尾字元是否相同進行計算即可。

#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=2e5+10;
ll n,l,r;
char s[N];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
	scanf("%d%s",&n,s);
	for(l=1;l<n && s[l]==s[0];l++);
	for(r=n-2;~r && s[r]==s[n-1];r--);r=n-r-1;
	if(s[0]==s[n-1])printf("%lld\n",(l+1)*(r+1)%mod);
	else printf("%lld\n",l+r+1);

	return 0;
}

C.Polygon for the Angle

我們作這個正 n n 邊形的外接圓,那麼可以得到對應圓心角的度數為 2 x 2x ,暴力列舉 n n 判斷即可。注意判 x &gt; 90 x&gt;90 的情況特殊處理。

#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 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
	int T=read();
	while(T--)
	{
		int x=read()*2;
		for(int i=3;i<=360;i++) 
			if(!(i*x%360) && (360/i!=(360-x))) {printf("%d\n",i);break;}
	}	
	return 0;
}

D.Easy Problem

f i , j f_{i,j} 表示前 i i 個字元匹配到第 j j 個的最小花費 DP \text{DP} 即可。

#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 N=1e5+10;
const ll INF=0x3f3f3f3f3f3f3f3f;
int n;
char s[N];
ll a[N],f[N][6];

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 id(char x)
{
	if(x=='h') return 1;
	else if(x=='a') return 2;
	else if(x=='r') return 3;
	else if(x=='d') return 4;
	return 0;
}

void gmin(ll &x,ll y){if(y<x)x=y;}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	n=read();scanf("%s",s+1);
	for(int i=1;i<=n;++i) a[i]=read();
	memset(f,0x3f3f,sizeof(f));f[0][0]=0;
	int flag=0;
	for(int i=1;i<=n;++i)
	{
		int x=id(s[i]);
		//printf("%d\n",x);
		if(!x) 
		{
			memcpy(f[i],f[i-1],sizeof(f[i-1]));
			continue; 
		}
		flag|=(1<<x-1);
		gmin(f[i][x],f[i-1][x-1]);
		gmin(f[i][x],f[i-1][x]);
		gmin(f[i][x-1],f[i-1][x-1]+a[i]);
		for(int j=0;j<x-1;++j) gmin(f[i][j],f[i-1][j]);
		for(int j=x+1;j<=4;++j)  gmin(f[i][j],f[i-1][j]);
	}

	if(flag^15){puts("0");return 0;}
	ll ans=INF; 
	//for(int j=1;j<=n;++j,puts(""))for(int i=0;i<=4;++i) printf("%lld ",f[j][i]);
	for(int i=0;i<4;++i) ans=min(ans,f[n][i]);
	printf("%lld\n",ans);

	return 0;
}

E.The Top Scorer

考慮列舉第一個人的權通過概率的定義進行計算,又由於存在權值相同的情況,我們需要列舉有多少個人的權與第一個人相同。現在問題就轉化為有若干個人的權和為某個值,且都小於某個值的方案數。而這個問題同樣可以通過列舉有多少個人等於最大值然後容斥進行計算。

#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=5500,mod=998244353;
int r,p,s,ans;
int C[N][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 qpow(int x,int y)
{
	int res=1;
	for(;y;y>>=1,x=(ll)x*x%mod) if(y&1) res=(ll)res*x%mod;
	return res;
}
int up(int &x,int y){x+=y;if(x>=mod)x-=mod;if(x<0)x+=mod;}
int upm(int x){return x>=mod?x-mod:x;}
void initC()
{
	for(int i=0;i<N;++i)
	{
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;++j) C[i][j]=upm(C[i-1][j]+C[i-1][j-1]); 
	}
}
int solve(int n,int k,int s)
{
	if(!n) return !s;
	int res=0;
	for(int i=0;i<=n && i*(k+1)<=s;++i)
		up(res,(ll)(i&1?-1:1)*C[n+s-i*(k+1)-1][n-1]*C[n][i]%mod);
	return res;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	initC();
	scanf("%d%d%d",&p,&s,&r);
	for(int i=r;i<=s;++i) for(int j=1;j<=p && i*j<=s;++j)//max&&the_same_as_max
		up(ans,(ll)qpow(j,mod-2)*solve(p-j,i-1,s-i*j)%mod*C[p-
            
           

相關推薦

CFEducational Codeforces Round 57

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

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

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

CFCodeforces Round #528 (Div. 1)

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

組合數學dpEducational Codeforces Round 51 (Rated for Div. 2) D. Bicolorings

Step1 Problem: 給你 2*n 的矩陣,你可以對於每個格子填塗黒色或者白色,如果相鄰顏色一樣看成同一塊,問你塗完後恰好有 k 塊的方案數。 資料範圍: 1 <= n <= 1000, 1 <= k <= 2n. Step2

CF Gym101623 NWERC2017

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

CFGood Bye 2018

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

浮*光Educational Codeforces Round 51 (Rated for Div. 2) A,B,C,D 題解

最少的操作使原串變成有數字+大小寫字母的串。 #include<iostream> #include<cstdio> #include<cstring> #i

CF Educational Codeforces Round 57劃水記

== 部分 ret 期望 直接 cat sin 歸並排序 怎麽 因為是unrated於是就叫劃水記了,而且本場也就用了1h左右。 A、B:劃水去了,沒做 C:大水題,根據初三課本中圓的知識,可以把角度化成弧長,而這是正多邊形,所以又可以化成邊數,於是假設讀入為a,就是周長的

Educational Codeforces Round 57 (Rated for Div. 2) 前三個

感慨 最終就做出來一個題,第二題差一點公式想錯了,又是一波掉分,不過我相信我一定能爬上去的 A Find Divisible(思維) 上來就T了,後來直接想到了題解的O(1)解法,直接輸出左邊界和左邊界*2即可 程式碼 #include <bits/stdc++.h> using nam

Educational Codeforces Round 57 Solution

A. Find Divisible 簽到。 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int t, l, r; 5 6 int main() 7 { 8 scanf("%d",

coderforces Educational Codeforces Round 57 A-D

在寢室睡了幾天以後過來做 自閉了 A題 題意 給你t組樣例 一個區間 l 到 r ,讓你輸出 l 到 r 內一對其中一個是另一個的因子的答案 , 保證題目有解 於是我們直接輸出左端點 和左端點乘2 即可 保證是最小的答案 #include <cstdio> #includ

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二場CF! 成績:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 題目:Educational Codeforces Round 57 (Rated for Div. 2) 錯題題解: D. Easy Problem E

Educational Codeforces Round 57 (Rated for Div. 2) ABCDF題解

ZZ出題人寫NTT寫成ZZ了吧,全是998244353,不需要取模的東西強行取模搞得我以為答案很大想了好久(指B題) A.任意輸出 \([l,r]\) 內的一組滿足 \(x \mid y\) 的 \(x, y\) ,保證有答案 我輸出了 \(\lfloor \frac{r}{l} \rfloor \tim

Educational Codeforces Round 57 (Rated for Div. 2) ABCDEF題解

題目總連結:https://codeforces.com/contest/1096 A. Find Divisible 題意: 給出l,r,在[l,r]裡面找兩個數x,y,使得y%x==0,保證有解。   題解: 直接輸出l,2*l就好啦,但我還是寫了個迴圈... 程式碼如下:

Educational Codeforces Round 57 (Rated for Div. 2) (待更新)

A.Find Divisible You are given a range of positive integers from l to r . Find such a pair of integers (x,y) that l≤x,y≤r , x≠y and x divides y .

CF1096F.Inversion Expectation[樹狀陣列+概率期望] Educational Codeforces Round 57

給一個排列(有些是-1,代表等概率是沒出現過數字中的任意一個),求期望逆序對個數 分成三部分(x表示已知) -1和-1之間的 -1和x之間的 x和x之間的 具體柿子在下面 ```cpp // -1 -1 cnt * (cnt - 1) / 2 / 2 // -1 x cnt(-1)

Codeforces Educational Codeforces Round 57 題解

sco 方程 -m 為什麽 break cat b- expec d+ 傳送門 Div 2的比賽,前四題還有那麽多人過,應該是SB題,就不講了。 這場比賽一堆計數題,很舒服。(雖然我沒打) E. The Top Scorer 其實這題也不難,不知道為什麽這麽少人過。 考慮

Educational Codeforces Round 57 (Rated for Div. 2) C 正多邊形 + 枚舉

Education while math 題意 block n-2 int ORC 枚舉 https://codeforces.com/contest/1096/problem/C 題意 問是否存在一正多邊形內三點構成的角度數為ang,若存在輸出最小邊數 題解 三點構

Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies暴力+細節

B. Vova and Trophies 題意 給你一個只有G,S兩種字元的字串,可以交換一次兩個位置的字元,問最終最長的連續的G可以有多少個 2