牛客2021年愚人节比赛 【题解】

很有意思的一套题,难度不大,不过题目很有意思。
比赛链接:https://ac.nowcoder.com/acm/contest/12800

目录

  • A: 出愚人节欢乐赛
  • B: 你这题,狗屁不通
  • C: 迁跃据数
  • D: qcjj的蝴蝶结1
  • E: qcjj的蝴蝶结2
  • F: qcjj背贯口
  • G: 诡异的七重咒印
  • H: 氵林女女的记录本
  • I: 数据跃迁

A: 出愚人节欢乐赛

只要代码没有编译错误都可以过,没有输出也可以过。

B: 你这题,狗屁不通

这道题考察的就是如何获取当前的时间并输出用到了一个_TIME_

#include
using namespace std;
int main(void)
{
     
    cout<<"2021/05/27 "<<__TIME__<<endl;
    return 0;
}

C: 迁跃据数

这道题和数据跃迁这道题是配套的。
我们需要通过数据跃迁来分析出这道题的结果。
牛客2021年愚人节比赛 【题解】_第1张图片
同过二分来排除,如果TLE说明结果在另一部分,以此来找答案。
最后会发现结果是866,通过哈希值求其原字符串。

#include
#include
#include
#include
using namespace std;
string ff(int sum)
{
     
	string a;
	while(sum)
	{
     
		a+=sum%4+'a';
		sum/=4; 
	}
	if(a.size()<5) a+="a";
	reverse(a.begin(),a.end());
	return a;
}
int main(void)
{
     
  
   	string ss=ff(866);
   	cout<<ss<<endl;
    return 0;
}

D: qcjj的蝴蝶结1

水题

#include
using namespace std;
int main(void)
{
     
    int t; cin>>t;
    while(t--)
    {
     
        int n; cin>>n;
        int ans=0;
        int a;
        for(int i=1;i<=n;i++){
     
            scanf("%d",&a);
            if(a%2) ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

E: qcjj的蝴蝶结2

暴力:枚举将其全部转换为每一种所需的花费,在其中取一个min就可以了。

#include
#include
#include
#include
using namespace std;
const int N=110;
int a[N];
int t,n,m;
int w[N][N];
int main(void)
{
     
	cin>>t;
	while(t--)
	{
     
		memset(w,-1,sizeof w);
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		cin>>m;
		for(int i=1;i<=m;i++) 
		{
     
			int x,y,z; cin>>x>>y>>z;
			w[x][y]=z;
		}
		long long int ans=1e18;
		for(int i=1;i<=n;i++)
		{
     
			long long int sum=0;
			bool flag=true;
			for(int j=1;j<=n;j++)
			{
     
				if(i==j) continue;//自己染成自己的情况
				if(w[j][i]==-1)//没有这种染色剂的情况
				{
     
					flag=false;
					break;
				}
				sum+=(long long int)a[j]*w[j][i];
			}
			if(flag) ans=min(ans,sum);
		}
        if(n==0) cout<<0<<endl;
		else if(ans==1e18) cout<<"qcjj yyds"<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

F: qcjj背贯口

刘备 关羽 张飞 赵云 徐庶 曹操 夏侯惇 颜良  8
马  龙   白龙马  白马   豹   虎  蛇   万里烟云兽  8
#include
using namespace std;
int main(void)
{
     
    cout<<8<<endl;
    cout<<8<<endl;
    cout<<16<<endl;
    return 0;
}

G: 诡异的七重咒印

牛客2021年愚人节比赛 【题解】_第2张图片

#include
using namespace std;
const int mod=1000000007;
typedef long long int LL;
LL n;
LL quick_pow(LL a,LL b,int c)
{
     
	LL res=1;
	while(b)
	{
     
		if(b&1) res=res*a%c;
		a=a*a%c;
		b=b>>1;
	}
	return res%c;
}
int main()
{
     
    scanf("%lld",&n);
    printf("%lld\n",n%mod);
    printf("%lld\n",(2*n-1)%mod);
    printf("%lld\n",(n%mod)*(n%mod)%mod);
    printf("%lld\n",quick_pow(2,n-1,mod));
    printf("%lld\n",quick_pow(2,quick_pow(2,n-1,mod-1),mod));
    printf(n&1?"1\n":"2\n");
    printf("%lld\n",(quick_pow(10,n,mod)-1)*quick_pow(9,mod-2,mod)%mod);
}

H: 氵林女女的记录本

1.许嵩 降温 281
2. 陈奕迅 第二次工业革命时期是19世纪中期,搜一下符合的只有 1874
3. 高晓松写给李宗盛的越过山丘歌词这个不是原歌词 20
4. 那英 王菲 1998
5. 周杰伦 发如雪 3000

#include
#include
using namespace std;
int main(void)
{
     
    cout<<281<<" "<<1874<<" "<<20<<" "<<1998<<" "<<3000<<endl;
    return 0;
}

I: 数据跃迁

通过C题来判断答案,还是用二分的方法,用一个死循环,来判断到底在哪一个区间。

#include
#include
#include
using namespace std;
int main(void)
{
     
    cout<<514<<endl;
    return 0;
}

你可能感兴趣的:(编程比赛,算法,c++)