Jobs (Easy Version)题解报告

题目

链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
 

Note: The only difference between the easy and the hard version is the constraints on nnn and mim_imi​.


Since Little Horse gets a golden prize in a programming contest, many companies send offers to him. There are nnn companies, and the iii-th company has mim_imi​ available jobs. To get an offer from a company, you need to be qualified for the job.

How to be qualified? The company will test your "three quotients": IQ (Intelligence Quotient), EQ (Emotional Quotient), and AQ (Adversity Quotient). Each job has three lower limits of the three quotients respectively. If all of your IQ, EQ, and AQ are no less than the corresponding lower limits, you are qualified for the job. As long as you are qualified for at least one job in a company, the company will send an offer to you.
 

Little Horse's three quotients are all high enough, so all the companies send offers to him. But Little Horse has qqq friends that worry about their jobs. Given the value of IQ, EQ and AQ of each friend, Little Horse wants to know how many companies will send offers to each friend.

In this problem, the IQEQ, and AQ of these qqq friends are generated as below.

First, register an mt19937\texttt{mt19937}mt19937 random engine rng\texttt{rng}rng with the seed\texttt{seed}seed and a uniform integer distribution object.

#include <random>
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1,400);

Then, the value of IQ, EQ, and AQ are generated as follows.

int lastans=0;
for (int i=1;i<=q;i++)
{
    int IQ=(u(rng)^lastans)%400+1;  // The IQ of the i-th friend
    int EQ=(u(rng)^lastans)%400+1;  // The EQ of the i-th friend
    int AQ=(u(rng)^lastans)%400+1;  // The AQ of the i-th friend
    lastans=solve(IQ,EQ,AQ);  // The answer to the i-th friend
}

输入描述:

The first line of input contains two integers n,qn,qn,q (1≤n≤101 \le n \le 101≤n≤10, 1≤q≤2×1061 \le q \le 2\times 10^61≤q≤2×106), indicating the number of companies and Little Horse's friends.

Then in the next nnn lines, the first integer of the iii-th line is mim_imi​ (1≤mi≤1051 \le m_i \le 10^51≤mi​≤105) --- the number of jobs in the iii-th company. Then there follow 3mi3m_i3mi​ integers. The jjj-th triple integers aj,bj,cja_j,b_j,c_jaj​,bj​,cj​ (1≤aj,bj,cj≤4001 \le a_j,b_j,c_j \le 4001≤aj​,bj​,cj​≤400) indicate the lower limits of IQ, EQ, and AQ for the jjj-th job in the iii-th company.

The next line contains one integer seed\text{seed}seed (108≤seed<23110^8\le \text{seed}<2^{31}108≤seed<231). Then the IQ ,EQ, and AQ of these qqq friends are generated as above.

输出描述:

Let's denote the answer to the iii-th friend as ansi\text{ans}_iansi​. You should output:

(∑i=1qansi⋅seedq−i) mod 998244353\left( \sum_{i=1}^q\text{ans}_i\cdot\text{seed}^{q-i} \right) \bmod 998244353(∑i=1q​ansi​⋅seedq−i)mod998244353

in a single line.

示例1

输入

3 5
2 1 1 2 2 1 2
3 1 3 2 2 3 1 2 3 3
2 2 3 1 3 2 1
191415411

输出

34417749

说明

The value of IQ, EQ, and AQ of the 555 friends in example are shown as follows.

92 108 303
116 36 265
255 132 185
360 219 272
8 115 254

The answers to each friend are all 333.
#include<bits/stdc++.h>
#include<random>
using namespace std;
#define ll long long
const ll mod=998244353;
int n,m,q,a[405][405][405],x,y,z,ans;
ll qpow(ll x,int p){
    ll ret=1;
    for(;p;p>>=1,x=x*x%mod)if(p&1)ret=ret*x%mod;
    return ret;
}
void dabiao(void)
{
	for(int i=1;i<=404;i++)
		for(int j=1;j<=404;j++)
			for(int k=1;k<=404;k++)
            {
				a[i][j][k]|=a[i-1][j][k];
				a[i][j][k]|=a[i][j-1][k];
				a[i][j][k]|=a[i][j][k-1];
			}
}
int main(){
	cin>>n>>q;
	for(int j=0;j<n;j++){
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>x>>y>>z;
			a[x][y][z]|=(1<<j);
		}
	}
	dabiao();
	ll seed;
	cin>>seed;
	std::mt19937 rng(seed);
	std::uniform_int_distribution<> u(1,400);
	ll lastans=0;
	for (int i=1;i<=q;i++){
    	int IQ=(u(rng)^lastans)%400+1;  // The IQ of the i-th friend
    	int EQ=(u(rng)^lastans)%400+1;  // The EQ of the i-th friend
    	int AQ=(u(rng)^lastans)%400+1;  // The AQ of the i-th friend
    	lastans=0;
    	for(int j=1;j<=n;j++)
            lastans+=a[IQ][EQ][AQ]>>(j-1)&1;
		ans=(ans+lastans%mod*qpow(seed,q-i)%mod)%mod;
	}
	cout<<ans;
}

(代码不精,大神勿喷)

求助大佬:但还有件事令我很疑惑,为什么下边这种写法只有30几分:

#include<bits/stdc++.h>
#include <random>
using namespace std;
typedef long long ll;
ll i,n,m,k,l,q,ans;
ll a[408][408][408];
ll iq[10][408],aq[10][408],eq[10][408];
ll company[19];
const ll mod=998244353;
void dabiao()
{
	for(ll i=1;i<=400;i++)
	{
		for(ll j=1;j<=400;j++)
		{
			for(ll k=1;k<=400;k++)
			{
				a[i][j][k]=a[i][j][k]|a[i-1][j][k]|a[i][j-1][k]|a[i][j][k-1];
			}
		}
	}
}
void print()
{
	for(ll i=1;i<=10;i++)
	{
		for(ll j=1;j<=10;j++)
		{
			for(ll k=1;k<=10;k++)
			{
				cout<<setw(2)<<a[i][j][k];
			}
			cout<<"\n";
		}
		cout<<"\n\n";
	}
}
ll pow(ll kk)
{
	ll j=1;
	for(i=1;i<=kk;i++)j*=2;
	return j;
}
ll pow1(ll seed,ll k)
{
	ll j=1;
	for(i=1;i<=k;i++)j=j*seed%mod;
	return j;
}
ll coun=0;
void f(ll g)
{
	if(g==1)
	{
		coun++;
		return ;
	}
	if(g==0)return;
	if(g%2==1)
	{
		coun++;
		f(g/2);
	}
	if(g%2==0)f(g/2);
}
ll solve(ll a1,ll b1,ll c1)
{
	coun=0;
	f(a[a1][b1][c1]);
	ll count1=coun;
	return count1;
}
int main()
{	
	cin>>n>>q;
	for(ll i=1;i<=n;i++)
	{
		cin>>company[i];
		for(ll j=1;j<=company[i];j++)
		{
			cin>>iq[i][j]>>eq[i][j]>>aq[i][j];
			a[iq[i][j]][eq[i][j]][aq[i][j]]|=pow(i-1);
		}
	}//print();
	dabiao();
//	print();
	ll seed;
	cin>>seed;
	std::mt19937 rng(seed);
	std::uniform_int_distribution<> u(1,400);
	ll lastans=0;
	for (int i=1;i<=q;i++)
	{
  	    int IQ=(u(rng)^lastans)%400+1;  // The IQ of the i-th friend
  	    int EQ=(u(rng)^lastans)%400+1;  // The EQ of the i-th friend
   	    int AQ=(u(rng)^lastans)%400+1;  // The AQ of the i-th friend
    	lastans=solve(IQ,EQ,AQ);  // The answer to the i-th friend
    	ans=(ans+lastans*pow1(seed,q-i)+mod)%mod;
	}
	cout<<ans;
}

看来看去似乎没什么区别,各位大神能帮看看嘛?谢谢!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值