Codeforces Round #404 (Div. 2)

本文探讨了几何形状计数问题的算法实现,通过输入不同几何体名称计算其面数总和;同时讨论了时间重叠区间计算问题,通过对两组时间段的输入,找出最大不重叠的时间长度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define pb push_back
#define mk make_pair
#define LL long long
#define REP(i, x, n)	for(int i = x; i < n; ++i)
#define mst(Arr, x)	memset(Arr, x, sizeof(Arr))
const int qq = 1e5 + 10;
int n;
int main(){
	cin >> n;
	string x;
	LL sum = 0;
	for(int i = 0; i < n; ++i){
		cin >> x;
		if(x == "Icosahedron")	sum += 4;
		else if(x == "Cube")	sum += 6;
		else if(x == "Octahedron")	sum += 8;
		else if(x == "Dodecahedron")	sum += 12;
		else	sum += 20;
	}
	printf("%lld\n", sum);
	return 0;
}

B

象棋時間可以在編程前也可以在編程後、所以統計兩種情況即可

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define pb push_back
#define mk make_pair
#define LL long long
#define REP(i, x, n)	for(int i = x; i < n; ++i)
#define mst(Arr, x)	memset(Arr, x, sizeof(Arr))
const int qq = 1e5 + 10;
int l, r, l1, r1;
int n, m;

int main(){
	scanf("%d", &n);
	int a, b;
	l = 1e9 + 10;
	l1 = -1;
	REP(i, 0, n){
		scanf("%d%d" ,&a, &b);
		l = min(l, b);
		r1 = max(r1, a);
	}
	r = -1;
	l1 = 1e9 + 10;
	scanf("%d", &m);
	REP(i, 0, m){
		scanf("%d%d", &a, &b);
		r = max(r, a);
		l1 = min(l1, b);
	}
	if(r - l <= 0 && r1 - l1 <= 0)	printf("0\n");
	else	printf("%d\n", max(r - l, r1 - l1));
	return 0;
}

C

這題是真的簡單、 就是有些算法結果會溢出、恰巧我推出了正確的式子寫的錯誤的算法

還拿錯誤的算法去hack別人正確的程序、QAQ

這題只討論n › m的情況

設f(x) 爲第 x天所剩下的糧食,因爲n大於m所以前m天糧食都會是滿的

f( m + 1 ) = n - ( m + 1 ) = n - m - 1

f(m + 2 ) = f( m + 1 ) + m - ( m + 2 ) = f( m + 1 ) - 2

..............

f(x ) = f( x - 1 ) + m - ( m + x ) = f( x - 1 ) - x

f(x ) = n - m + ( 1 + x ) * x / 2


即求最小的x使得f(x)小於等於0

注意結果還要加上m


#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define pb push_back
#define mk make_pair
#define LL long long
#define REP(i, x, n)	for(int i = x; i < n; ++i)
#define mst(Arr, x)	memset(Arr, x, sizeof(Arr))
const int qq = 1e5 + 10;
LL n, m;
bool check(LL x, LL k){
	LL sum = (1LL + x) * x / 2;
	if(k - sum <= 0)	return true;
	return false;
}

int main(){
	scanf("%lld%lld", &n, &m);
	if(n <= m){
		printf("%lld\n", n);
		return 0;
	}
	n -= m;
	n *= 2LL;
	LL d = sqrt(n);
	while(d * (d + 1) < n)	d++;
	printf("%lld\n", d + m);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值