DAY3 CF重现

CF重现赛

A. Two distinct points

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given two segments [l1;r1][l1;r1] and [l2;r2][l2;r2] on the xx-axis. It is guaranteed that l1<r1l1<r1 and l2<r2l2<r2. Segments may intersect, overlap or even coincide with each other.

The example of two segments on the xx-axis.
Your problem is to find two integers aa and bb such that l1≤a≤r1l1≤a≤r1, l2≤b≤r2l2≤b≤r2 and a≠ba≠b. In other words, you have to choose two distinct integer points in such a way that the first point belongs to the segment [l1;r1][l1;r1] and the second one belongs to the segment [l2;r2][l2;r2].

It is guaranteed that the answer exists. If there are multiple answers, you can print any of them.

You have to answer qq independent queries.

Input
The first line of the input contains one integer qq (1≤q≤5001≤q≤500) — the number of queries.

Each of the next qq lines contains four integers l1i,r1i,l2il1i,r1i,l2i and r2ir2i (1≤l1i,r1i,l2i,r2i≤109,l1i<r1i,l2i<r2i1≤l1i,r1i,l2i,r2i≤109,l1i<r1i,l2i<r2i) — the ends of the segments in the ii-th query.

Output
Print 2q2q integers. For the ii-th query print two integers aiai and bibi — such numbers that l1i≤ai≤r1il1i≤ai≤r1i, l2i≤bi≤r2il2i≤bi≤r2i and ai≠biai≠bi. Queries are numbered in order of the input.

It is guaranteed that the answer exists. If there are multiple answers, you can print any.

Example
inputCopy
5
1 2 1 2
2 6 3 4
2 4 1 3
1 2 1 3
1 4 5 8
outputCopy
2 1
3 4
3 2
1 2
3 7

思路&过程

在区间枚举,不同就结束

#include<iostream>
 using namespace std;
 int main()
 {
 	long long n,l1,l2,r1,r2,i,j,k;
 	bool t;
	cin>>n;
	for(k=1;k<=n;k++)
	{
		cin>>l1>>r1>>l2>>r2;
		t=true;
		i=l1;
		while(t&&(i<=r1)){
			j=l2;
			while(t&&(j<=r2))
			{
				if(i!=j) 
				{
					t=false;
					cout<<i<<" "<<j<<endl;
				}
				j=j+1;
			}
			i=i+1;
		}
	}
	return 0;
 }

B. Divisors of Two Integers

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Recently you have received two positive integer numbers xx and yy. You forgot them, but you remembered a shuffled list containing all divisors of xx (including 11 and xx) and all divisors of yy (including 11 and yy). If dd is a divisor of both numbers xx and yy at the same time, there are two occurrences of dd in the list.

For example, if x=4x=4 and y=6y=6 then the given list can be any permutation of the list [1,2,4,1,2,3,6][1,2,4,1,2,3,6]. Some of the possible lists are: [1,1,2,4,6,3,2][1,1,2,4,6,3,2], [4,6,1,1,2,3,2][4,6,1,1,2,3,2] or [1,6,3,2,4,1,2][1,6,3,2,4,1,2].

Your problem is to restore suitable positive integer numbers xx and yy that would yield the same list of divisors (possibly in different order).

It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers xx and yy.

Input
The first line contains one integer nn (2≤n≤1282≤n≤128) — the number of divisors of xx and yy.

The second line of the input contains nn integers d1,d2,…,dnd1,d2,…,dn (1≤di≤1041≤di≤104), where didi is either divisor of xx or divisor of yy. If a number is divisor of both numbers xx and yy then there are two copies of this number in the list.

Output
Print two positive integer numbers xx and yy — such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.

Example
inputCopy
10
10 2 8 1 2 4 1 20 4 5
outputCopy
20 8

思路&过程

找到最大那个就是答案之一,之后再从大往小搜,第一个不是它的因子的就是另一个

#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

int main()
{
	int n,a[200],i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	bool t=true;
	i=n;
	while((i>=1)&&t)
	{
		if(a[i-1]==a[i]||a[n]%a[i]!=0)
		{
			cout<<a[n]<<" "<<a[i];
			t=false;
		}
		i=i-1;
	}
	return 0;
}

C. Nice Garland

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi (‘R’, ‘G’ and ‘B’ — colors of lamps in the garland).

You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is nice.

A garland is called nice if any two lamps of the same color have distance divisible by three between them. I.e. if the obtained garland is tt, then for each i,ji,j such that ti=tjti=tj should be satisfied |i−j| mod 3=0|i−j| mod 3=0. The value |x||x| means absolute value of xx, the operation x mod yx mod y means remainder of xx when divided by yy.

For example, the following garlands are nice: “RGBRGBRG”, “GB”, “R”, “GRBGRBG”, “BRGBRGB”. The following garlands are not nice: “RR”, “RGBG”.

Among all ways to recolor the initial garland to make it nice you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

Input
The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of lamps.

The second line of the input contains the string ss consisting of nn characters ‘R’, ‘G’ and ‘B’ — colors of lamps in the garland.

Output
In the first line of the output print one integer rr — the minimum number of recolors needed to obtain a nice garland from the given one.

In the second line of the output print one string tt of length nn — a nice garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

Examples
inputCopy
3
BRB
outputCopy
1
GRB
inputCopy
7
RGBGRBB
outputCopy
3
RGBRGBR

思路&过程

前三个定了,后面次序唯一。穷举前三个单词可能的排列,找到次数最少的那一种。

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
char a[6][4]={"RGB","RBG","BRG","BGR","GRB","GBR"};
long long n,m,i,j,k,ans,g,minn=1e8;
char str[200010];

int f(char *a)
{
	int c=0,gg=0,i,j;
	for(i=0;i<n;i++)
	{
		if(str[i]!=a[gg]) c=c+1;
		gg=(gg+1)%3;
	}
	return c;
}

int main()
{
	cin>>n;
	cin>>str;
	for(i=0;i<6;i++)
	{
		if(f(a[i])<minn)
		{
			minn=f(a[i]);
			ans=i;
		}
	}
	cout<<minn<<endl;
	int g=0;
	for(i=0;i<n;i++)
	{
		cout<<a[ans][g];
		g=(g+1)%3;
	}
	return 0;
}

D. Diverse Garland

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi (‘R’, ‘G’ and ‘B’ — colors of lamps in the garland).

You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.

A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 11) have distinct colors.

In other words, if the obtained garland is tt then for each ii from 11 to n−1n−1 the condition ti≠ti+1ti≠ti+1 should be satisfied.

Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

Input
The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of lamps.

The second line of the input contains the string ss consisting of nn characters ‘R’, ‘G’ and ‘B’ — colors of lamps in the garland.

Output
In the first line of the output print one integer rr — the minimum number of recolors needed to obtain a diverse garland from the given one.

In the second line of the output print one string tt of length nn — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

Examples
inputCopy
9
RBGRRBRGG
outputCopy
2
RBGRGBRGR
inputCopy
8
BBBGBRRR
outputCopy
2
BRBGBRGR
inputCopy
13
BBRRRRGGGGGRR
outputCopy
6
BGRBRBGBGBGRG

思路&过程

连续两个一样的话根据下一个变动两个中的后一个,三个一样只要变中间就行。

#include<iostream>
using namespace std;
int main()
{
	int n,m,i,j,sum,ans;
	char s[200010];
	cin>>n;
	cin>>s;
	ans=0;
	for(i=0;i<n-1;i++)
	{
		if(s[i]==s[i+1])
		{
			ans=ans+1;
			if(s[i]=='R')
			{
				if(i+2<n && s[i+2]!='B') s[i+1]='B';
				else s[i+1]='G';
			}
			else if(s[i]=='B')
			{
				if(i+2<n && s[i+2]!='R') s[i+1]='R';
				else s[i+1]='G';
			}
			else if(s[i]=='G')
			{
				if(i+2<n && s[i+2]!='B') s[i+1]='B';
				else s[i+1]='R';
			}
		}
	}
	cout<<ans<<endl;
	cout<<s;
	return 0;
}
后记

总用时一时零三分
Arwen要去吃饭啦,就打一半咯。
没有男朋友的Arwen又只能胡乱解决啦,羡慕舍友,嘤。

// pages/stats/stats.js const eventBus = require(&#39;../../utils/event-bus.js&#39;); Page({ data: { loading: true, dataType: 0, dataTypes: [&#39;步数&#39;, &#39;饮水&#39;, &#39;睡眠&#39;], years: [&#39;2023&#39;, &#39;2024&#39;, &#39;2025&#39;], months: [&#39;01&#39;, &#39;02&#39;, &#39;03&#39;, &#39;04&#39;, &#39;05&#39;, &#39;06&#39;, &#39;07&#39;, &#39;08&#39;, &#39;09&#39;, &#39;10&#39;, &#39;11&#39;, &#39;12&#39;], selectedYear: &#39;2025&#39;, selectedMonth: &#39;06&#39;, statsData: { average: 0, max: 0, completion: 0 }, chartData: { labels: [], values: [] }, // 添加重绘标志 needRedraw: false }, onLoad() { // 初始化事件总线 this.initEventBus(); // 设置默认日期为当前年月 const now = new Date(); this.setData({ selectedYear: now.getFullYear().toString(), selectedMonth: (now.getMonth() + 1).toString().padStart(2, &#39;0&#39;) }, () => { this.loadStats(); }); }, // 初始化事件总线(关键修复) initEventBus() { this.dataUpdatedListener = () => { console.log(&#39;收到数据更新事件,重新加载统计&#39;); this.loadStats(); }; eventBus.on(&#39;healthDataUpdated&#39;, this.dataUpdatedListener); }, onUnload() { eventBus.off(&#39;healthDataUpdated&#39;, this.dataUpdatedListener); }, onShow() { // 页面显示时强制重绘 if (this.data.needRedraw) { this.setData({ needRedraw: false }, () => { setTimeout(() => this.drawChart(), 100); }); } }, // 加载统计数据(关键修复) loadStats() { const app = getApp(); const records = app.getAllRecords(); const filteredRecords = this.filterRecordsByMonth(records); // 准备图表数据 const chartData = this.prepareChartData(filteredRecords); // 计算统计数据 const statsData = this.calculateStats(filteredRecords); this.setData({ statsData, chartData, loading: false, needRedraw: true // 设置重绘标志 }, () => { // 等待视图更新后绘制 setTimeout(() => { this.drawChart(); }, 300); }); }, // 修复日期筛选逻辑 filterRecordsByMonth(records) { const { selectedYear, selectedMonth } = this.data; return records.filter(record => { const [year, month] = record.date.split(&#39;-&#39;); const normalizedMonth = month.padStart(2, &#39;0&#39;); return year === selectedYear && normalizedMonth === selectedMonth; }).sort((a, b) => new Date(a.date) - new Date(b.date)); }, // 准备图表数据 prepareChartData(records) { const labels = []; const values = []; records.forEach(record => { const day = record.date.split(&#39;-&#39;)[2]; labels.push(`${parseInt(day)}`); // 直接映射类型字段 const typeMap = { 0: &#39;steps&#39;, 1: &#39;water&#39;, 2: &#39;sleep&#39; }; const typeKey = typeMap[this.data.dataType]; values.push(typeKey ? record[typeKey] || 0 : 0); }); return { labels, values }; }, // 计算统计数据 calculateStats(records) { if (!records || records.length === 0) { return { average: 0, max: 0, completion: 0 }; } // 直接映射类型字段 const typeMap = { 0: &#39;steps&#39;, 1: &#39;water&#39;, 2: &#39;sleep&#39; }; const typeKey = typeMap[this.data.dataType]; const values = records.map(r => r[typeKey] || 0); const sum = values.reduce((acc, val) => acc + val, 0); const average = values.length > 0 ? (sum / values.length).toFixed(1) : 0; const max = Math.max(...values); const app = getApp(); const userInfo = app.globalData.userInfo; let target = 0; switch (this.data.dataType) { case 0: target = userInfo.target_steps || 10000; break; case 1: target = userInfo.target_water || 2.5; break; case 2: target = userInfo.target_sleep || 8; break; } let completion = 0; if (target > 0 && average > 0) { completion = (average / target) * 100; completion = Math.min(100, completion).toFixed(0); } return { average, max, completion }; }, // 切换数据类型 changeDataType(e) { this.setData({ dataType: e.detail.value }, () => { this.loadStats(); }); }, // 切换年份 changeYear(e) { this.setData({ selectedYear: this.data.years[e.detail.value] }, () => { this.loadStats(); }); }, // 切换月份 changeMonth(e) { this.setData({ selectedMonth: this.data.months[e.detail.value] }, () => { this.loadStats(); }); }, // 关键修复:确保Canvas正确销毁和重绘 drawChart() { // 销毁旧Canvas上下文 if (this.ctx) { try { this.ctx = null; } catch (e) { console.warn(&#39;Canvas上下文销毁异常&#39;, e); } } // 创建新Canvas上下文 this.ctx = wx.createCanvasContext(&#39;chartCanvas&#39;); const { labels, values } = this.data.chartData; // 清除画布 this.ctx.clearRect(0, 0, 320, 200); this.ctx.draw(true); if (labels.length === 0) { console.log(&#39;无数据,跳过绘图&#39;); return; } const canvasWidth = 320; const canvasHeight = 200; const paddingLeft = 45; const paddingTop = 25; const paddingRight = 25; const paddingBottom = 35; const chartWidth = canvasWidth - paddingLeft - paddingRight; const chartHeight = canvasHeight - paddingTop - paddingBottom; // 绘制坐标轴 this.ctx.beginPath(); this.ctx.moveTo(paddingLeft, paddingTop); this.ctx.lineTo(paddingLeft, paddingTop + chartHeight); this.ctx.lineTo(paddingLeft + chartWidth, paddingTop + chartHeight); this.ctx.strokeStyle = &#39;#ddd&#39;; this.ctx.stroke(); // 确定最大值 let maxValue = Math.max(...values, 1); // 确保最小值至少为1 // 根据数据类型调整最大值 if (this.data.dataType === 0) maxValue = Math.max(maxValue, 50000); else if (this.data.dataType === 1) maxValue = Math.max(maxValue, 5); else if (this.data.dataType === 2) maxValue = Math.max(maxValue, 12); // 绘制数据点和折线 const pointRadius = 4; const dataPoints = []; for (let i = 0; i < values.length; i++) { const x = paddingLeft + (i / (labels.length - 1)) * chartWidth; const y = paddingTop + chartHeight - (values[i] / maxValue) * chartHeight; dataPoints.push({ x, y }); this.ctx.beginPath(); this.ctx.arc(x, y, pointRadius, 0, Math.PI * 2); this.ctx.fillStyle = &#39;#2c9cf1&#39;; this.ctx.fill(); this.ctx.font = &#39;10px sans-serif&#39;; this.ctx.fillStyle = &#39;#666&#39;; this.ctx.textAlign = &#39;center&#39;; this.ctx.fillText(labels[i], x, paddingTop + chartHeight + 15); } // 绘制折线 this.ctx.beginPath(); this.ctx.moveTo(dataPoints[0].x, dataPoints[0].y); for (let i = 1; i < dataPoints.length; i++) { this.ctx.lineTo(dataPoints[i].x, dataPoints[i].y); } this.ctx.strokeStyle = &#39;#2c9cf1&#39;; this.ctx.lineWidth = 2; this.ctx.stroke(); // 绘制值标签 for (let i = 0; i < values.length; i++) { let displayValue; switch (this.data.dataType) { case 0: displayValue = `${values[i]}步`; break; case 1: displayValue = `${values[i]}L`; break; case 2: displayValue = `${values[i]}小时`; break; default: displayValue = values[i].toString(); } this.ctx.font = &#39;10px sans-serif&#39;; this.ctx.fillStyle = &#39;#2c9cf1&#39;; this.ctx.textAlign = &#39;center&#39;; this.ctx.fillText(displayValue, dataPoints[i].x, dataPoints[i].y - 10); } // 绘制Y轴刻度 this.ctx.font = &#39;10px sans-serif&#39;; this.ctx.fillStyle = &#39;#666&#39;; this.ctx.textAlign = &#39;right&#39;; this.ctx.textBaseline = &#39;middle&#39;; for (let i = 0; i <= 3; i++) { const value = (maxValue * (3 - i) / 3).toFixed(1); const y = paddingTop + (chartHeight * i) / 3; this.ctx.beginPath(); this.ctx.moveTo(paddingLeft - 5, y); this.ctx.lineTo(paddingLeft, y); this.ctx.strokeStyle = &#39;#ddd&#39;; this.ctx.stroke(); this.ctx.fillText(value, paddingLeft - 8, y); } // 确保绘制完成 this.ctx.draw(true); } }); 页面中完成率不管数值多少默认显示100,太离谱了,然后切换一下页面完成率就一直是0了,让完成率的计算变正常,可以用取巧的方法
最新发布
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值