codeforces Round#350 Div.2

本文解析了一场CF编程挑战赛中的四道题目,包括确定火星年休假天数、机器人游戏、电影院选择及制作饼干问题,提供了详细的算法思路和代码实现。

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

  打了一场实时cf。。事实证明本来就不聪明,打到3点真tmd够呛

 

A. Holidays
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.

Output

Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.

Examples
Input
14
Output
4 4
Input
2
Output
0 2
Note

In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly4 days off .

In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.

题意: 意思是火星上一周7天(5个工作日,2天周末),给你一个n表示有n天,输出这n天里最少和最多的休息天数。

大水题不过我还wa了一发。。后来就交不了题了(可能是网不好也可能是刷网页的人太多了。。)n天对week取整除和取余,据此判断最少和最多的天数(注意余数是6或者1的情况)。

直接贴代码吧,没啥好说的。。

/*
 * A.cpp
 *
 *  Created on: 2016年5月5日
 *      Author: Triose
 */
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//	freopen("Out.txt", "w", stdout);
#endif
	while(~sf(n)) {
		int a = n / 7;
		int b = n % 7;
		pfd((a * 2 + (b > 5 ? b - 5 : 0)), (a * 2 + (b >= 2 ? 2 : b)));
	}
	return 0;
}


B. Game of Robots
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from1 to 109.

At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until then-th robot says his identifier.

Your task is to determine the k-th identifier to be pronounced.

Input

The first line contains two positive integers n andk (1 ≤ n ≤ 100 000,1 ≤ k ≤ min(2·109, n·(n + 1) / 2).

The second line contains the sequence id1, id2, ..., idn (1 ≤ idi ≤ 109) — identifiers of roborts. It is guaranteed that all identifiers are different.

Output

Print the k-th pronounced identifier (assume that the numeration starts from1).

Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note

In the first sample identifiers of robots will be pronounced in the following order:1, 1, 2. As k = 2, the answer equals to 1.

In the second test case identifiers of robots will be pronounced in the following order:10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to4.

这道题简直就是脑子不清醒就不要推公式的典范!

意思是给你n个数,按照一定的顺序(第i次报前i个)排列,输出第m个数。。。

   1

  1 2

 1 2 3                              =>  1 12 123 1234(数字代表a[i])

1 2 3 4

.....

别想着推公式了,即使是O(n)也能过!不要追求O(1)

/*
 * B.cpp
 *
 *  Created on: 2016年5月5日
 *      Author: Triose
 */
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//	freopen("Out.txt", "w", stdout);
#endif
	while(~sfd(n,m)) {
		int i = 1;
		while(m > i) {
			m -= i;
			i++;
		}
		int tmp, ans;
		for(i = 1; i <= n; i++) {
			sf(tmp);
			if(i == m) {
				ans = tmp;
			}
		}
		pf(ans);
	}
	return 0;
}

C. Cinema
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from1 to 109.

In the evening after the conference, all n scientists decided to go to the cinema. There arem movies in the cinema they came to. Each of the movies is characterized by twodistinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will bevery pleased if he knows the audio language of the movie, will bealmost satisfied if he knows the language of subtitles and will benot satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different).

Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists.

The second line contains n positive integersa1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which thei-th scientist knows.

The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.

The fourth line contains m positive integersb1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of thej-th movie.

The fifth line contains m positive integersc1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of thej-th movie.

It is guaranteed that audio languages and subtitles language are different for each movie, that isbj ≠ cj.

Output

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.

If there are several possible answers print any of them.

Examples
Input
3
2 3 2
2
3 2
2 3
Output
2
Input
6
6 3 1 1 3 7
5
1 2 3 4 5
2 3 4 5 1
Output
1
Note

In the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.

In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactlytwo scientists will be very pleased and all the others will be not satisfied.


题意:有三个数列a,b,c,分别表示科学家们会的语言的编号, 电影声音的语言编号, 电影字幕的语言编号。 输出电影序号使得能听懂语言的数目最大,如果有多个这样的电影,那就输出(其中)使得能看懂字幕的科学家数目最大的电影序号。。(好吧我知道我说的很含糊不过就大概是这个意思了吧。。)

因为n的数据范围是1 ~ 2*10^5, 语言的范围是:1 ~ 10^9。  这时候肯定是离散分布的,不可能每种语言都有! 所以自然而然想到用map统计每种语言的人数。然后设法求出最大值(可以排序,也可以便利)。

傻逼就傻逼在我们两个人都选择了nlogn的排序!却没想到O(n)的便利!!!(两傻逼住一寝室久了就tm犯蠢的方式都一样了!)

看到那日本选手代码的时候我们下巴都快掉下来了!是这么写的啊!为什么人家没超时?后来一看才发现,人家可没排序。。。

贴代码吧。。。

/*
 * C.cpp
 *
 *  Created on: 2016年5月5日
 *      Author: Triose
 */
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<map>
#include<set>
using namespace std;
//#define ONLINE_JUDGE
#define eps 1e-8
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define rep(i,a) for((i)=0; i<(a);(i)++)
#define mem(a,b) (memset((a),b,sizeof(a)))
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sfs(a) scanf("%s",a)
#define pf(a) printf("%d\n",a)
#define pfd(a,b) printf("%d %d\n",a,b)
#define pfs(a) printf("%s\n",a)
#define pfI(a) printf("%I64d\n",a)
#define enter putchar(10)
#define LL __int64
const double PI = acos(-1.0);
const double E = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b)*b; }
template<class T> inline T Min(T a, T b) { return a<b ? a : b; }
template<class T> inline T Max(T a, T b) { return a>b ? a : b; }
int n, m;
#define N 200010
int a[N];
int b[N];
int c[N];
map<int, int>mp;
bool cmp(int u, int v) {
	if(mp[b[u]] != mp[b[v]])
		return mp[b[u]] > mp[b[v]];
	return mp[c[u]] > mp[c[v]];
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//	freopen("Out.txt", "w", stdout);
#endif
	while(~sf(n)) {
		mp.clear();
		for(int i = 0; i < n; i++) {
			sf(a[i]);
			mp[a[i]]++;
		}
		sf(m);
		for(int i = 0; i < m; i++) {
			sf(b[i]);
		}
		for(int i = 0; i < m; i++) {
			sf(c[i]);
		}
		int ans = 0;
		for(int i = 1; i < m; i++) {
			if(cmp(i, ans)) {
				ans = i;
			}
		}
		pf(ans + 1);
	}
	return 0;
}



输入的时候就统计,便利输出就ok。。

D1. Magic Powder - 1
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.

Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needsn ingredients, and for each ingredient she knows the valueai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use alln ingredients.

Apollinaria has bi gram of thei-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly1 gram of any of the n ingredients and can be used for baking cookies.

Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.

Input

The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where the i-th number is equal to the number of grams of thei-th ingredient, needed to bake one cookie.

The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 1000), where the i-th number is equal to the number of grams of thei-th ingredient, which Apollinaria has.

Output

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

Examples
Input
3 1
2 1 4
11 3 16
Output
4
Input
4 3
4 3 5 6
11 12 14 20
Output
3
Note

In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.

In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index1 and 1 gram of magic powder to ingredient with the index3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.


题意: 大水题。。 数据范围大概就1000, 意思是:要做饼干需要n种材料,做成一个饼干需要若干个i材料(a[i]), 你现在有这n种材料各若干个( b[i] ),你还有k个万能替代品(可以替代任何一种材料)。现在问你,用上这些替代品你最多能做出多少个饼干?


对于这种小数据,当然是怎么暴力怎么来。。输入的时候求得最少能做多少个饼干(min_ans = Min(min_ans, b[i] / a[i])),然后在这个最小值的基础上每次多加1,直到k小于0就能得出最大值。。(当然这是小数据的做法)O(k * n)

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
#define N 1010
template<class T> T Min(T a, T b) {return a > b ? b : a;}
int n,k;
int a[N];
int b[N];
int main() {
    while(cin >> n >> k) {
	int ans = 100000;
	for(int i = 0; i < n; i++)
	    cin >> a[i];
	for(int i = 0; i < n; i++) {
	    cin >> b[i];
	    ans = Min(ans, b[i] / a[i]);
	}
	
	int tmp = ans + 1;
	while(k >= 0) {
	    for(int i = 0; i < n; i++) {
		if(b[i] >= tmp * a[i])
		    continue;
		k -= (a[i] * tmp - b[i]);
		b[i] = a[i] * tmp;
	    }
	    if(k >= 0)
		ans = tmp;
	    tmp++;
	}
	
    	cout << ans << endl;
    }
    return 0;
}

D2, 题目意思完全没变,只不过换成了大数据。既然故意换数据,那么肯定卡了你的O(k * n), 你至少得优化到O(n * log k)才行吧?这时一个很自然的想法就是二分。实际上也就是这么做的。。最小值min_ans 如D1所述,那么max_ans 等于多少呢? max_ans = Max(max_ans ,  ((b[i] + k) / a[i]) + 1),反正二分嘛,多加个1也无所谓。然后找一个mid使得现有替代品数量能做mid个饼干,但是不能做mid + 1块饼干。此时mid就是最终答案。贴代码吧, 这题也巨简单。。

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
template<class T>
T Min(T a, T b) {
    return a > b ? b : a;
}
template<class T>
T Max(T a, T b) {
    return a > b ? a : b;
}
#define N 100010
#define LL long long
LL a[N];
LL b[N];
int n,k;
int check(LL mid, int tmpk) {
    int tmp = tmpk;
    for(int i = 0; i < n; i++) {
	if(b[i] >= a[i] * mid) continue;
	tmp -= (a[i] * mid - b[i]);
	if(tmp < 0)
	    return -1;
    }
    tmp = tmpk; mid++;
    for(int i = 0; i < n; i++) {
	if(b[i] >= a[i] * mid) continue;
	tmp -= (a[i] * mid - b[i]);
	if(tmp < 0)
	    return 0;
    }
    return 1;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","r", stdin);
#endif
    while(cin >> n >> k) {
	//cout << n << " " << k << endl;
	LL min_ans = INF;
	LL max_ans = -1;
	for(int i = 0; i < n; i++)
	    cin >> a[i];
	for(int i = 0; i < n; i++) {
	    cin >> b[i];
	    min_ans = Min(min_ans, b[i] / a[i]);
	    max_ans = Max(max_ans, ((b[i] + k) / a[i]) + 1);
	}
	//cout << check(132, k) << endl;
	//cout << max_ans << endl;
	if(check(max_ans, k) >= 0) {
	    cout << max_ans << endl;
	    continue;
	}
	LL mid_ans = (max_ans + min_ans) >> 1;
	while(min_ans < max_ans) {
	    mid_ans = (max_ans + min_ans) >> 1;
	    //cout << mid_ans << endl;
	    switch (check(mid_ans, k)) {
		case -1: max_ans = mid_ans; break;
		case 0: min_ans = max_ans; break;
		case 1: min_ans = mid_ans; break;
	    }
	}
	cout << mid_ans << endl;
    }
    return 0;
}


因为是用vim写的所以有很多注释,那是调试的时候用的。。




总结:比赛的时候就做出了前两题,无奈。可能也是能力不足。。但是这种难度做出5个也完全没有问题啊!后面两题我还会找时间再做做。。今天就先写到这吧

1.晚上不要打代码

2.能tm便利就不要tmd排序

3.从O(n)到O(log n)最常用的一个办法就是二分!


标题基于SpringBoot+Vue的学生交流互助平台研究AI更换标题第1章引言介绍学生交流互助平台的研究背景、意义、现状、方法与创新点。1.1研究背景与意义分析学生交流互助平台在当前教育环境下的需求及其重要性。1.2国内外研究现状综述国内外在学生交流互助平台方面的研究进展与实践应用。1.3研究方法与创新点概述本研究采用的方法论、技术路线及预期的创新成果。第2章相关理论阐述SpringBoot与Vue框架的理论基础及在学生交流互助平台中的应用。2.1SpringBoot框架概述介绍SpringBoot框架的核心思想、特点及优势。2.2Vue框架概述阐述Vue框架的基本原理、组件化开发思想及与前端的交互机制。2.3SpringBoot与Vue的整合应用探讨SpringBoot与Vue在学生交流互助平台中的整合方式及优势。第3章平台需求分析深入分析学生交流互助平台的功能需求、非功能需求及用户体验要求。3.1功能需求分析详细阐述平台的各项功能需求,如用户管理、信息交流、互助学习等。3.2非功能需求分析对平台的性能、安全性、可扩展性等非功能需求进行分析。3.3用户体验要求从用户角度出发,提出平台在易用性、美观性等方面的要求。第4章平台设计与实现具体描述学生交流互助平台的架构设计、功能实现及前后端交互细节。4.1平台架构设计给出平台的整体架构设计,包括前后端分离、微服务架构等思想的应用。4.2功能模块实现详细阐述各个功能模块的实现过程,如用户登录注册、信息发布与查看、在线交流等。4.3前后端交互细节介绍前后端数据交互的方式、接口设计及数据传输过程中的安全问题。第5章平台测试与优化对平台进行全面的测试,发现并解决潜在问题,同时进行优化以提高性能。5.1测试环境与方案介绍测试环境的搭建及所采用的测试方案,包括单元测试、集成测试等。5.2测试结果分析对测试结果进行详细分析,找出问题的根源并
内容概要:本文详细介绍了一个基于灰狼优化算法(GWO)优化的卷积双向长短期记忆神经网络(CNN-BiLSTM)融合注意力机制的多变量多步时间序列预测项目。该项目旨在解决传统时序预测方法难以捕捉非线性、复杂时序依赖关系的问题,通过融合CNN的空间特征提取、BiLSTM的时序建模能力及注意力机制的动态权重调节能力,实现对多变量多步时间序列的精准预测。项目不仅涵盖了数据预处理、模型构建与训练、性能评估,还包括了GUI界面的设计与实现。此外,文章还讨论了模型的部署、应用领域及其未来改进方向。 适合人群:具备一定编程基础,特别是对深度学习、时间序列预测及优化算法有一定了解的研发人员和数据科学家。 使用场景及目标:①用于智能电网负荷预测、金融市场多资产价格预测、环境气象多参数预报、智能制造设备状态监测与预测维护、交通流量预测与智慧交通管理、医疗健康多指标预测等领域;②提升多变量多步时间序列预测精度,优化资源调度和风险管控;③实现自动化超参数优化,降低人工调参成本,提高模型训练效率;④增强模型对复杂时序数据特征的学习能力,促进智能决策支持应用。 阅读建议:此资源不仅提供了详细的代码实现和模型架构解析,还深入探讨了模型优化和实际应用中的挑战与解决方案。因此,在学习过程中,建议结合理论与实践,逐步理解各个模块的功能和实现细节,并尝试在自己的项目中应用这些技术和方法。同时,注意数据预处理的重要性,合理设置模型参数与网络结构,控制多步预测误差传播,防范过拟合,规划计算资源与训练时间,关注模型的可解释性和透明度,以及持续更新与迭代模型,以适应数据分布的变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值