1. 程式人生 > >【CodeForces】CodeForces Round #512 (Div. 1) 題解

【CodeForces】CodeForces Round #512 (Div. 1) 題解

【比賽連結】

【題解連結】

**【A】**Vasya and Triangle

【思路要點】

  • 任何三格點角形的面積均是 0.5 0.5 的整數倍,因此當 2
    N M 2*N*M
    不是 k k
    的倍數,問題無解。
  • 否則,令 g = g c d ( N
    , k ) , t n p = N g , t m p = M g k g=gcd(N,k),tnp=\frac{N}{g},tmp=\frac{M*g}{k}
  • 選取 ( 0 , 0 ) , ( 2 t n p , 0 ) , ( 0 , t m p ) (0,0),(2*tnp,0),(0,tmp) ( 0 , 0 ) , ( t n p , 0 ) , ( 0 , 2 t m p ) (0,0),(tnp,0),(0,2*tmp) 中合法的一個作為答案。
  • 時間複雜度 O ( L o g V ) O(LogV)

【程式碼】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
ll n, m, k;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
int main() {
	read(n), read(m), read(k);
	ll g = gcd(n, k);
	k = k / g;
	if (m * 2 % k != 0) printf("NO\n");
	else {
		ll x = n / g, y = m * 2 / k;
		if (y > m) x *= 2, y /= 2;
		printf("YES\n");
		printf("0 0\n");
		cout << x << ' '<< 0 << endl;
		cout << 0 << ' ' << y << endl;
	}
}

**【B】**Vasya and Good Sequences

【思路要點】

  • A i A_i 表示 a i a_i 二進位制表示中 1 1 的個數。
  • 一個序列 [ l , r ] [l,r] 合法當且僅當 M a x i = l r { A i } i = l r A i 2 Max_{i=l}^{r}\{A_i\}≤\frac{\sum_{i=l}^{r}A_i}{2} i = l r A i \sum_{i=l}^{r}A_i 2 2 的倍數。
  • 注意到 M a x i = l r { A i } 64 Max_{i=l}^{r}\{A_i\}≤64 ,列舉左端點 l l ,列舉滿足 r l + 128 r≤l+128 的右端點,用字尾和處理剩餘的 r r
  • 時間複雜度 O ( N L o g A i ) O(NLogA_i)

【程式碼】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a[MAXN], s[MAXN][2], sum[MAXN], nxt[MAXN];
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++) {
		ll tmp; read(tmp);
		while (tmp) {
			a[i] += tmp & 1;
			tmp >>= 1;
		}
	}
	for (int i = 1; i <= n; i++){
		sum[i] = sum[i - 1] + a[i];
		s[i][1] = s[i - 1][1];
		s[i][0] = s[i - 1][0];
		if (sum[i] % 2 == 1) s[i][1]++;
		else s[i][0]++;
	}
	int las = n + 1;
	for (int i = n; i >= 0; i--){
		nxt[i] = las;
		if (a[i] != 0) las = i;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++){
		int tmp = sum[i - 1] % 2;
		int las = i, Max = a[i], sum = a[i];
		for (int j = 1; j <= 128; j++){
			int id = nxt[las]; 
			if (sum / 2 >= Max){
				ans = ans + s[id - 
            
           

相關推薦

CodeForcesCodeForces Round #512 (Div. 1) 題解

【比賽連結】 點選開啟連線 【題解連結】 點選開啟連結 **【A】**Vasya and Triangle 【思路要點】 任何三格點角形的面積均是

CodeForcesCodeForces Round #406 (Div. 1) 題解

【比賽連結】 點選開啟連線 【題解連結】 點選開啟連結 **【A】**Berzerk 【思路要點】 博弈搜尋,將狀態按先後手拆點,建出遊戲圖。 若一個點存在出邊指向必敗態,則

CodeForcesCodeForces Round #511 (Div. 1) 題解

【比賽連結】 點選開啟連線 【題解連結】 點選開啟連結 **【A】**Enlarge GCD 【思路要點】 令所有數的

CodeForcesCodeForces Round #516 (Div. 1) 題解

【比賽連結】 點選開啟連線 【題解連結】 點選開啟連結 **【A】**Oh Those Palindromes 【思路要點】 一個字串是迴文串的一個必要條件是該字串的第一個字元與最後

題解Codeforces 1063:Round #516 (Div. 1, by Moscow Team Olympiad) ABC

總結 字串排序後的迴文子串數最多,為ΣNx(Nx+1)/2\Sigma N_x(Nx+1)/2ΣNx​(Nx+1)/2 bfs獲得下一步狀態時,選擇遍歷常數陣列與分別列舉中適合的方案。 A. Oh Those Palindromes 迴文串,結論 給定一個

Codeforces Educational Round 54 Div. 2 A-G

傳送門:cf1076 A. Minimizing the String 貪心刪去第一個字典序大於後一個位置的字母的位置。 #include<bits/stdc++.h> using namespace std; int n; char s[200005];

Codeforces Round #512 (Div. 1) B. Vasya and Good Sequences

粘不過來題目,自己點開看吧QAQ 題目大意:給你一列數,現在有一種操作,就是對一個數,可以任意交換其二進位制的兩位,操作次數不限。問你有多少個字串 [ l , r ],可以經過上述操作,使該字串的異或和為0。 題解: 一段數的異或和為0,即讓這一串數二進位制下每

Codeforces Round #512 Div. 1 B. Vasya and Good Sequences 分治

Description 給你一個序列,問有多少個區間[l,r]滿足l~r的每一個數01隨意排列異或和為0。 Sample Input 3 6 7 14 Sample Output 2 你可以發現一個性質: 一個區間內的數總和為偶數,且總和大於最大的數乘二就

Codeforces Round #516 (Div. 1) 題解

直線 () force ans ces 相互 wap col efi A.Oh Those Palindromes 直接排序之後輸出就行了。 證明的話直接跟據同一種字符最多能在多少個回文串中貢獻答案就行了。 #include <bits/stdc++.h> #

CodeChefSeptember Challenge 2018 (Div. 1 + Div. 2) 題解

【比賽連結】 點選開啟連線 **【ANDSQR】**AND Square Subsegments 【思路要點】 離線詢問,按左端點排序。 列舉區間的左端點

CodeChefOctober Challenge 2018 (Div. 1 + Div. 2) 題解

【比賽連結】 點選開啟連線 **【BBRICKS】**Beautiful Bricks 【思路要點】 上下兩個磚塊中,至多有一個黑色。 連續的一段存在黑色的行共有兩種放置的方案。 列舉有幾段連續的存在黑色的

洛谷 P3374 模板樹狀數組 1 題解

數字 pri getchar 說明 using 完全 ace getc ret 此文為博主原創題解,轉載時請通知博主,並把原文鏈接放在正文醒目位置。 題目鏈接:https://www.luogu.org/problem/show?pid=3374 題目描述 如題,

ContestNowcoder 假日團隊賽1 題解+賽後總結

比賽連結 通過順序:\(B\rightarrow D\rightarrow I\rightarrow J\rightarrow G\rightarrow H \rightarrow A \rightarrow K\rightarrow C\rightarrow E \rightarrow L \rightar

推導Codeforces Round #411 (Div. 1) A. Find Amir

div sca ace space for amp clu ret blog 1 2 3 4 5 6 7 4-5-3-6-2-7-1 答案是(n-1)/2 #include<cstdio> using namespace std; int n; int mai

貪心 Codeforces Round #419 (Div. 1) A. Karen and Game

blog true 刪除 round 貪心 cnblogs pac names namespace 容易發現,刪除的順序不影響答案。 所以可以隨便刪。 如果行數大於列數,就先刪列;否則先刪行。 #include<cstdio> #include<algo

找規律遞推二項式定理Codeforces Round #419 (Div. 1) B. Karen and Test

main turn logs pow 分享 string ren () 奇數 打個表出來看看,其實很明顯。 推薦打這倆組 11 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 10000000

推導貪心Codeforces Round #431 (Div. 1) A. From Y to Y

aaa return 最大的 tchar 題意 spa 必須 puts clu 題意:讓你構造一個只包含小寫字母的可重集,每次可以取兩個元素,將它們合並,合並的代價是這兩個元素各自的從‘a’到‘z’出現的次數之積的和。 給你K,你構造的可重集必須滿足將所有元素合而為一以後,

codeforces比賽題解#868 CF Round #438 (Div.1+Div.2)

這一 一行 mes 無限 解鎖 col 道路 ces 然而 這次是Div.1+Div.2,所以有7題。 因為時間較早,而且正好趕上訓練,所以機房開黑做。 然而我們都只做了3題。:(。 鏈接。 【A】聲控解鎖 題意: Arkady的寵物狗Mu-mu有一只手機。它需要朝這個手機

做題Codeforces Round #453 (Div. 1) D. Weighting a Tree——拆環

每一個 int 會有 while sig 實現 dex -s 怎麽辦 前言:結論題似乎是我的硬傷…… 題意是給你一個無向圖,已知連接到每一個點的邊的權值和(為整數,且屬於區間[-n,n]),需要求出每條邊權值的一個合法解(都要是在區間[-2*n^2,2*n^2]內的整數)。

Codeforces Round #239 (Div. 1) ATriangle

div urn end ont stdin a* 題意 sqrt 是不是 【鏈接】 我是鏈接,點我呀:) 【題意】 在這裏輸入題意 【題解】 最後的直角三角形可以通過平移,將直角頂點移動到坐標原點。 然後我們只要枚舉另外兩個點其中一個點的坐標就好了。 x坐標