2020.9.19选拔

4281 Problem A GoGo向前冲

在这里插入图片描述

//答案错误
#include<bits/stdc++.h>
using namespace std;
const int N=10010;
string s;
int main(){
	getline(cin,s);
	int len=s.length()-1;
	int st=s.find('F');
	int en=s.find('S');
	//cout<<st<<" "<<en;
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++){
		int num;
		cin>>num;
		if(st+num==en){
			cout<<"true";
			return 0;
		}
		else if(st+num>len)
		{
			st=len*2-num-st;
		}else{
			st=st+num;
		}
		if(st==en){
			cout<<"true";
			return 0;
		}else{
			cout<<"false";
			return 0;
		}
	} 
}
//学长代码
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	string str;
	cin>>str;
	int s,e,l;
	l=str.length();
	for(int i=0;i<str.length();i++)
	{
		if(str[i]=='F') s=i+1;
		if(str[i]=='S') e=i+1;
	}
	int n,a;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(s+a>l)
		{
			s=2*l-(a+s);
		}
		else s+=a;
		if(s == e) {
			cout << "true";
			return 0;
		}
	}
	cout<<"false";
	return 0;
}

4282 Problem B 密码解析(正确)

在这里插入图片描述
把 . 换成空格

#include<bits/stdc++.h>
using namespace std;
const int N=10010;

int main(){
	string str;
	getline(cin,str);
	for(int i=0;i<str.length();i++){
		if(str[i]=='.'){
			cout<<" ";
		}
		else{
			cout<<str[i];
		}
	}
}

4283 Problem C 三体

在这里插入图片描述
我的思路是:先把6个面的全算上,然后再看竖排,每竖排如果有4个就是有3个共面就是少3*2个被盖住的,就是那个for循环的公式
然后再把竖排当成整体,每个竖排和前后左右相邻的竖排是取最小的高度算遮挡面,然后就是把n * n个竖排全遍历一遍,把前后左右的都减了

//运行错误
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=10010;
ll arr[N][N];
ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};


int main(){
	ll n,sum=0;cin>>n;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			cin>>arr[i][j];
		}
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			sum+=(arr[i][j]*6-2*(arr[i][j]-1));
			
		}
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			for(ll index=0;index<4;index++){
				if(i+dx[index]>=0&&j+dy[index]>=0&&i+dx[index]<n&&j+dy[index]<n){
					sum-=min(arr[i][j],arr[i+dx[index]][j+dy[index]]);
				}
			}
		}
	}
	cout<<sum;
}
//把数组开小一点,就是答案错误了,好像是有些测试点漏了
//!!0的话,多加了2!!

//学长代码
#include <bits/stdc++.h>
#define dx i + dir[k]
#define dy j + dir[k + 1]
using namespace std;
int dir[] = {0, -1, 0, 1, 0};
int a[105][105];
int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			cin >> a[i][j];
		}
	}
	int sum = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(a[i][j]) {
				sum += 4 * a[i][j] + 2;
				for(int k = 0; k < 4; ++k) {
					if(dx >= 0 && dx < n && dy >= 0 && dy < n) {
						sum -= min(a[dx][dy], a[i][j]);
					}
				}
			}
		}
	}
	cout << sum;
	return 0;
}

4284 Problem D 请不要用sort(正确)

在这里插入图片描述

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

int a[100100];
int main(){
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll i=0;i<n;i++){
		for(ll j=i;j<n;j++)
		{
			if(a[i]>a[j])
			{
				swap(a[i],a[j]);
			}
		}
	}
	for(ll i=0;i<n-1;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[n-1];	
}
//学长代码
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int a[100005]={0};
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n,[&](int a,int b){
		return a<b;
	});
	for(int i=0;i<n;i++)
	{
		if(i!=0) cout<<" ";
		cout<<a[i];
	}
	return 0;
}

4287 Problem E 数字根2(正确)

在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10010;

int  main(){
	ll n,sum=0;
	int f=1;
	cin>>n;
	while(f){
		while(n){
			sum+=n%10;
			n/=10;
		}
		if(sum<10){
			f=0;
			cout<<sum;
			return 0;
		}else{
			n=sum;
			sum=0;
		}
	}
	return 0;
}
//学长代码1
#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long n,sum=10,l,t=1; int cnt;
	scanf("%lld",&n);
	while(sum>=10)
	{	
		sum=0;
		while(t!=0)
		{	
			l=n%10;
			t=n/10;
			n=n/10;
			sum=sum+l;
		}
		n=sum;
		t=1;
	}
	cout<<sum;
	return 0;
}
//学长代码2
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n;
	cin >> n;
	if(n < 10) cout << n;
	else if(n % 9) cout << n % 9;
	else cout << 9;
	return 0;
}

4285 Problem F Ackermann function

在这里插入图片描述
在这里插入图片描述

//时间超限
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;
int t;

int A(int m,int n){
	if(m==0){
		return n+1; 
	} else if(m>0&&n==0){
		return A(m-1,1);
	}else{
		return A(m-1,A(m,n-1));
	}
} 

int main(){
	cin>>t;
	for(int i=0;i<t;i++)
	{
		int n,m;
		cin>>m>>n;
		cout<<A(m,n)<<endl;
	}
}
//学长代码1
#include<iostream>
using namespace std;
int main(){
	int t,x,y;
	cin>>t;
	for(int i=0;i<t;i++){
		cin>>x>>y;
		if(x==0)	cout<<y+1<<endl;
		else if(x==1)	cout<<y+2<<endl;
		else if(x==2)	cout<<2*y+3<<endl;
		else if(x==3)	cout<<(1<<(y+3))-3<<endl;
	}	
return 0;
}
//学长代码2
#include<bits/stdc++.h>
using namespace std;
int A(int m,int n) {
    if(n==0&&m!=0) return A(m-1,1);
    else if(m==0)return n+1;
    else if(m==1) return n+2;
    else if(m==2) return 2*n+3;
//    else  if(m==3)return A(m,n-1)*2+3;
  else if(m==3) return (1<<n+3)-3;
}
int main() {
//  freopen("test1.in","r",stdin);
//  freopen("test1.out","w",stdout);
    int t;
    cin >> t;
    for(int j=1; j<=t; ++j) {
        int m,n;
        cin >> m >> n;
        cout << A(m,n) << endl;
    }
    return 0;
}

4286 Problem G 消失的元素

在这里插入图片描述

//运行错误
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;

ll n,arr[N];
int bo[N]={0};

int main(){
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		bo[arr[i]]=1;
	}
	for(int i=0;i<=n;i++){
		if(bo[i]==0)cout<<i<<" ";
	}
}
//学长代码
#include<bits/stdc++.h>
using namespace std;
int missingNumber(int nums[],int n) {
	int res = 0;
// 先和新补的索引异或?下
	res ^= n;
// 和其他的元素、索引做异或
	for (int i = 0; i < n; i++)
		res ^= i ^ nums[i];
	return res;
}
int a[1000005];
int main() {
//	freopen("1.in","r",stdin);
	int n;
	cin >> n;

	for(int i=0;i<n;++i){
		cin >> a[i];
	}
	cout << missingNumber(a,n);

	return 0;
}

小结

【运行错误】可以考虑把数组开小一点

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DDouble-

你的鼓励是我最大的动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值