主頁 >  其他 > Codeforces Round 871 (Div. 4)

Codeforces Round 871 (Div. 4)

2023-05-09 08:06:45 其他

A.Love Story

題意:

給定n個長度為10的字串,問其與codeforces字串的對應下標字母不同的個數,

分析:

對于每個字串從前往后依次和“codeforces”對應字符比較然后統計不同字母數即可

code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	string s = "codeforces";
	
	int t;
	cin >> t;
	
	while (t --)
	{
		string s2;
		cin >> s2;
		
		int cnt = 0;
		for (int i = 0; i < 10; i ++)
			if (s2[i] != s[i])
				cnt ++;
		
		cout << cnt << endl;	
	} 
	
	return 0;
}
 

B. Blank Space

題意:

給定長度為n的陣列,問連續相鄰為0的最大長度

分析:

維護一個全域最大長度res,和當前連續序列的長度cnt,從前往后掃描序列,若當前元素為0則更新cnt,否則更新res并重置cnt為0

code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	
	while (t --)
	{
		int n;
		cin >> n;
		
		int res = 0, cnt = 0; 
		for (int i = 0; i < n; i ++)
		{
			int a;
			cin >> a;
			
			if (a == 0)
				cnt ++;
			else
			{
				res = max(res, cnt);
				cnt = 0;
			}
		}
		
		res = max(res, cnt);
		
		cout << res << endl;
	} 
	
	return 0;
}
 

C. Mr. Perfectly Fine

題意:

給定n個二元組,第一個數為花費,第二個是一個長度為2的01串,第一位為1表示含有1技能,第二位為1表示含有2技能,問最少需要花費多少才能獲得這兩個技能即用最少的花費得到字串11?

分析:

由于“00,01,10,11”分別表示“0,1,2,3”,所以為了方便處理我直接用數字表示字串,
首先預處理排個序,優先按花費從小到大排序,若花費相同則按技能數值從大到小排序(能優先得到3自然不需要用1和2來湊)
然后我們考慮以下情況:①第一次選到3②第一次選到1③第一次選到2,這三種情況誰先發生并有解,誰就是最優解,

code:

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
struct Book
{
	int t, skill;
}book[N];

bool cmp(Book A, Book B)
{
	if (A.t != B.t)
		return A.t < B.t;
	else
		return A.skill > B.skill;
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	int t;
	cin >> t;
	
	while (t --)
	{
		int n;
		cin >> n;
		
		for (int i = 0; i < n; i ++)
		{
			string s;
			cin >> book[i].t >> s;
			int skill = 0;
			if (s == "00")
				skill = 0;
			else if (s == "01")
				skill = 1;
			else if (s == "10")
				skill = 2;
			else
				skill = 3;
			book[i].skill = skill; 
		}
		
		sort(book, book + n, cmp);
		
		int res = 0x3f3f3f3f;
		bool a = false, b = false, c = false;
		for (int i = 0; i < n; i ++)
		{
			if (book[i].skill == 0)
				continue;
				
			if (a && b && c)
				break;
			
			if (book[i].skill == 3)
			{
				if (!a)
				{
					res = min(res, book[i].t);
					a = true;
					break;
				}
			}
			
			if (book[i].skill == 1)
			{
				if (!b)
				{
					for (int j = i + 1; j < n; j ++)
					{
						if (book[j].skill == 2)
						{
							res = min(res, book[i].t + book[j].t);
							break;
						}
					}
					b = true;
				}
			}
			
			if (book[i].skill == 2)
			{
				if (!c)
				{
					for (int j = i + 1; j < n; j ++)
					{
						if (book[j].skill == 1)
						{
							res = min(res, book[i].t + book[j].t);
							break;
						}
					}
					c = true;
				}
			}
		}
		
		if (res == 0x3f3f3f3f)
			cout << -1 << endl;
		else
			cout << res << endl;
	} 
	
	return 0;
}
 

D. Gold Rush

題意:

給你兩個數n和m,n可以拆成兩個數a和b,需要滿足:a + b = n,且其中一個數a(或b)需為另一個數b(或a)的2倍,問是否能拆出m來,

分析:

首先得明確如果n能按題目劃分則n必須得是3的倍數,然后dfs搜索一下所有劃分方案看是否有解即可

code:

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

bool dfs(int n, int m)
{
	if (n == m)
		return true;
	
	if (n % 3 != 0)
		return false;
	int a = n / 3;
	int b = a * 2;
	
	if (a == m || b == m)
		return true;
	
	if (m > b)
		return false;
	else
	{
		if (dfs(b, m))
			return true;
		else if (m > a)
			return false;
		
		if (dfs(a, m))
			return true;
	}
	
	return false;
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	int t;
	cin >> t;
	
	while (t --)
	{
		int n, m;
		cin >> n >> m;
		
		if (dfs(n, m))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	} 
	
	return 0;
}
 

E. The Lakes

題意:

給定n * m的地圖,每個點都有一個非負數的權值,定義湖泊區域為不包含值為0的連通區域(上下左右任意聯通即可),問其中點權值和最大的湖泊區域所對應的值為多少,

分析:

經典的flood-fill模型,可以用bfs做也可以用dfs做,

code:

#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second

typedef pair<int, int> PII;
typedef long long LL;

const int N = 1010;
int g[N][N];
bool st[N][N];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, m;

LL bfs(int sx, int sy)
{
	queue<PII> q;
	LL res = g[sx][sy];
	q.push({sx, sy});
	st[sx][sy] = true;
	
	while (q.size())
	{
		auto t = q.front();
		q.pop();
		
		int x = t.x, y = t.y;
		
		for (int i = 0; i < 4; i ++)
		{
			int x1 = x + dx[i], y1 = y + dy[i];
			
			if (x1 < 0 || x1 > n || y1 < 0 || y1 > m || g[x1][y1] == 0 || st[x1][y1])
				continue;
				
			res += g[x1][y1];
			st[x1][y1] = true;
			q.push({x1, y1});
		}
	}
	
	return res;
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	int t;
	cin >> t;
	
	while (t --)
	{
		cin >> n >> m;
		
		LL res = 0;
		for (int i = 0; i < n; i ++)
		{
			for (int j = 0; j < m; j ++)
			{
				cin >> g[i][j];
				st[i][j] = false;
			}
		}
		
		for (int i = 0; i < n; i ++)
		{
			for (int j = 0; j < m; j ++)
			{
				if (g[i][j] == 0 || st[i][j])
					continue;
				res = max(res, bfs(i, j));
			}
		}
		
		cout << res << endl;
	} 
	
	return 0;
}
 

F. Forever Winter

題意:

給定一個雪花圖,問滿足這個圖要求的x和y是多少?
1.1個點連接著x個其他的點,
2.這x個點又分別連接著y個點,
image

分析:

找規律,我們可以發現,設度為1的結點總數為n,則n = x * y,于是我們可以用unordered_map記錄所有存在的度數,列舉n的因數x,y,若度數x和度數y + 1存在或者度數y和度數x + 1存在,則x和y就是滿足要求的解,

code:

#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second

typedef pair<int, int> PII;
typedef long long LL;

const int N = 210;
int d[N];

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	int t;
	cin >> t;
	
	while (t --)
	{
		int n, m;
		cin >> n >> m;
		unordered_map<int, bool> mp;
		memset(d, 0, sizeof d);
		
		while (m --)
		{
			int a, b;
			cin >> a >> b;
			
			d[a] ++, d[b] ++;
		}
		
		int cnt = 0;
		for (int i = 1; i <= n; i ++)
		{
			if (d[i] == 1)
				cnt ++;
			mp[d[i]] = true;
		}
		
		for (int i = 2; i * i <= cnt; i ++)
		{
			if (cnt % i == 0)
			{
				int j = cnt / i;
				
				if (mp[i] && mp[j + 1])
				{
					cout << i << " " << j << endl;
					break;
				}
				else if (mp[i + 1] && mp[j])
				{
					cout << j << " " << i << endl;
					break;
				}
			}
		}
	} 
	
	return 0;
}
 

G. Hits Different

題意:

給你2023行數,第i行有i個數,如果一個數被“擊倒”,則會影響上面與其相鄰的數(也會被“擊倒”),影響會一直向上擴散,問被擊倒的這些數的和為多少,
image

分析:

①首先分析,擊中一個數n它會影響到哪些數?這里可以找規律,可以發現數字是和層數相關的:第i層[l,r]將會影響到第i - 1層的[l - i, r - i + 1],當然這里要注意邊界,第i層的數n應當滿足:i * (i - 1) / 2 + 1 <= n <= i * (i + 1) / 2,所以設L = l - i, R = r - i + 1, I = i - 1;那么L = max(L, I * (I - 1) / 2 + 1), R = min(R, I * (I + 1) / 2),
②既然知道會影響哪些數,那么怎么求和呢?快速求一個區間的和我們自然想到用前綴和來處理,
③最后分析如何確定一個數所在的層數,根據上面分析第i層的數n應當滿足:i * (i - 1) / 2 + 1 <= n <= i * (i + 1) / 2,可以通過看n是否滿足 floor * (floor + 1) / 2的二段性來二分查找,

code:

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long LL;

const int N = 1e6 + 5;
LL s[N];

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	for (LL i = 1; i < N; i ++)
		s[i] = s[i - 1] + i * i;
		
	int t;
	cin >> t;
	
	while (t --)
	{
		LL n;
		cin >> n;
		
		int l = 1, r = 2023;
		while (l < r)
		{
			int mid = l + r >> 1;
			if (n <= mid * (mid + 1) / 2)
				r = mid;
			else
				l = mid + 1;
		}
		int p = r;
		
		LL res = n * n;
		l = r = n;
		while (p > 1)
		{
			l = l - p;
			r = r - p + 1;
			p --;
			r = min(r, p * (p + 1) / 2);
			l = max(l, p * (p - 1) / 2 + 1);
			res += s[r] - s[l - 1];
		}
		
		cout << res << endl;
	}
	
	return 0;
}
 

H. Don't Blame Me

題意:

給定n個數,問有多少種子序列相與,結果的二進制中有k個1,

分析:

由于0 <= n <= 63,63已經是6位1了因此再怎么相與也不會超過63,所以我們可以先求出所有子序列相與結果為0-63的所有方案,然后從0-63中選出二進制有k個1的方案,其方案數之和即為答案,“求從n個數里選一些數使其相與結果為m的方案數”,這就是一個類01背包問題,
狀態:f[i][j]表示從前i個數中選一些數,使其相與結果為j的方案數,
轉移:
①不選第i個數:f[i][j] += f[i - 1][j];
②選第i個數: f[i][j & a[i]] += f[i - 1][j];
因為已知a & b = c,并不能推出c & b = a,所以②不能寫成f[i][j] += f[i - 1][j & a[i]];

code:

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const int N = 2e5 + 5, M = 65, mod = 1e9 + 7;
LL f[N][M];
int a[N];

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	
	int t;
	cin >> t;
	
	while (t --)
	{
		int n, k;
		cin >> n >> k;
		
		for (int i = 1; i <= n; i ++)
			cin >> a[i];
			
		for (int i = 1; i <= n; i ++)
			for (int j = 0; j <= 63; j ++)
				f[i][j] = 0;
		
		for (int i = 1; i <= n; i ++)
		{
			f[i][a[i]] = 1;
			
			for (int j = 0; j <= 63; j ++)
			{
				f[i][j] = (f[i][j] + f[i - 1][j]) % mod;
				f[i][j & a[i]] = (f[i][j & a[i]] + f[i - 1][j]) % mod;	
			}	
		} 
		
		LL res = 0;
		for (int i = 0; i <= 63; i ++)
		{
			int m = i, len = 0;
			
			while (m)
			{
				if (m & 1)
					len ++;
				m >>= 1;
			}
			
			if (len == k)
				res = (res + f[n][i]) % mod;
		}
		
		cout << res << endl;
	}
	
	return 0;
}
 

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/551933.html

標籤:其他

上一篇:5分鐘實作呼叫ChatGPT介面API實作多輪問答

下一篇:返回列表

標籤雲
其他(158656) Python(38123) JavaScript(25405) Java(18024) C(15222) 區塊鏈(8262) C#(7972) AI(7469) 爪哇(7425) MySQL(7171) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5871) 数组(5741) R(5409) Linux(5336) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4567) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2432) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1965) Web開發(1951) HtmlCss(1932) python-3.x(1918) 弹簧靴(1913) C++(1912) xml(1889) PostgreSQL(1874) .NETCore(1857) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • Codeforces Round 871 (Div. 4)

    A.Love Story 題意: 給定n個長度為10的字串,問其與codeforces字串的對應下標字母不同的個數。 分析: 對于每個字串從前往后依次和“codeforces”對應字符比較然后統計不同字母數即可 code: #include <bits/stdc++.h> using name ......

    uj5u.com 2023-05-09 08:06:45 more
  • 5分鐘實作呼叫ChatGPT介面API實作多輪問答

    5分鐘實作呼叫ChatGPT介面API完成多輪問答 最近ChatGPT也是火爆例外啊,在親自使用了幾個月之后,我發現這東西是真的好用,實實在在地提高了生產力。那么對于開發人員來說,有時候可能需要在自己的代碼里加入這樣一個智能問答的功能,我最近就出現了這樣的想法和需求,所以簡單研究了一下。網上類似的方 ......

    uj5u.com 2023-05-09 08:06:16 more
  • 昇騰實戰丨DVPP媒體資料處理視頻解碼問題案例

    摘要:本期就分享幾個關于DVPP視頻解碼問題的典型案例,并給出原因分析及解決方法 本文分享自華為云社區《DVPP媒體資料處理視頻解碼問題案例》,作者:昇騰CANN 。 DVPP(Digital Vision Pre-Processing)是昇騰AI處理器內置的影像處理單元,通過AscendCL媒體數 ......

    uj5u.com 2023-05-09 08:06:09 more
  • 外譯筆記 | 比爾蓋茨:AI與智能手機和互聯網一樣具有革命性

    這篇文章,值得關注的是,蓋茨提出對人工智能如何可以減少世界上最嚴重的不公平現象的思考,以及我們關注的人工智能風險問題。 ......

    uj5u.com 2023-05-09 08:06:03 more
  • 試用「ChatGPT」幾周之后

    把「ChatGPT」當做工具,假設當你的專業能力足夠深入時;它能不能提供有價值的資訊,是個問題;你是不是能相信它所提供的資訊,目前來看,也是個問題; ......

    uj5u.com 2023-05-09 08:05:16 more
  • 云原生周刊:Kubernetes 1.27 服務器端欄位校驗和 OpenAPI V3 進階

    開源專案推薦 KubeView KubeView 是一個 Kubernetes 集群可視化工具和可視化資源管理器。它允許用戶在集群內部運行命令,并查看集群內部的資源使用情況、容器運行狀態、網路流量等。KubeView 支持多種資料源,可以讀取 Prometheus、Grafana、Kubernete ......

    uj5u.com 2023-05-09 08:03:49 more
  • 讀書筆記丨理解和學習事務,讓你更好地融入云原生時代

    摘要:分布式事務與云原生技術有很強的關聯,可以幫助云原生應用程式實作高效的分布式事務處理。 本文分享自華為云社區《理解和學習事務,讓你更好地融入云原生時代》,作者: breakDawn。 隨著云原生的概念越來越火,服務的架構應該如何發展和演進,成為很多程式員關心的話題。大名鼎鼎的《深入理解java虛 ......

    uj5u.com 2023-05-09 08:03:42 more
  • 當Serverless遇到Regionless:現狀與挑戰

    摘要:本文嘗試基于分析現有的學術文章,剖析Serverless與Regionless并存時,在性能提升和成本控制兩個方向的現狀與挑戰 本文分享自華為云社區《當Serverless遇到Regionless:現狀與挑戰》,作者:云容器大未來。 近年來,Serverless服務崛起的趨勢是有目共睹的:從B ......

    uj5u.com 2023-05-09 08:03:28 more
  • 環形佇列的實作 [詳解在代碼中]

    1 package DataStructures.Queue.Array.Exerice; 2 3 /** 4 * @author Loe. 5 * @project DataStructures&Algorithms 6 * @date 2023/5/8 7 * @ClassInfo 環形佇列 8 ......

    uj5u.com 2023-05-09 08:02:57 more
  • Codeforces Round 871 (Div. 4)

    A.Love Story 題意: 給定n個長度為10的字串,問其與codeforces字串的對應下標字母不同的個數。 分析: 對于每個字串從前往后依次和“codeforces”對應字符比較然后統計不同字母數即可 code: #include <bits/stdc++.h> using name ......

    uj5u.com 2023-05-09 08:02:49 more