1. 程式人生 > 其它 >2022/12 做題記錄 #1

2022/12 做題記錄 #1

2022/12/9

P7550 [COCI2020-2021#6] Bold

https://www.luogu.com.cn/problem/P7550

沒啥說的,如果從前往後遍歷,就要開兩個陣列,具體見程式碼。

#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[1100][1100],b[1100][1100];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(a[i][j]=='#')
			{
				b[i][j]='#';
				b[i+1][j]='#';
				b[i][j+1]='#';
				b[i+1][j+1]='#';
			}
			else if(b[i][j]!='#') b[i][j]='.';
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		cout<<b[i][j];
		cout<<endl;
	}
    return 0;
}

P8822 [傳智杯 #3 初賽] 課程報名

https://www.luogu.com.cn/problem/P8822

注意迴圈內兩個語句的順序,是先報名,再漲價。

#include<bits/stdc++.h>
using namespace std;
int n,v,m,a;
long long ans=0;
int main()
{
	cin>>n>>v>>m>>a;
	for(int i=1;i<=n;i++)
	{
		ans+=v;
		if(i%m==0) v+=a;
	}
	cout<<ans<<endl;
	return 0;
}