“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
Posted 小哈里
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL相关的知识,希望对你有一定的参考价值。
题号 标题 已通过代码 通过率 团队的状态
A Task Computing 点击查看 283/1578
B 2D Internet Angel 点击查看 13/151
C Easy Counting Problem 点击查看 105/510
D Jobs (Easy Version) 点击查看 799/4606
E Jobs (Hard Version) 点击查看 30/169
F Palindromic Tree 点击查看 1/32
G Wall Builder I 点击查看 21/586
H Wall Builder II 点击查看 670/1491
I Three Body 点击查看 9/22
J Counting Fish Again 点击查看 33/172
K NIO’s Sword 点击查看 950/6341
L Black Hole 点击查看 219/1186
M Monotone Chain 点击查看 45/405
N Particle Arts 点击查看 1300/6645
文章目录
N.Particle Arts
链接:https://ac.nowcoder.com/acm/contest/33189/N
来源:牛客网
题目描述
(PDF statement: https://pan.baidu.com/s/1txNBj0tHp-DVWadoBROvPA?pwd=gc8c)
In a confined NIO space, there are nn NIO particles, the ii-th of which has a_ia
i
joule energy. The NIO particles are very special as they keep colliding with each other randomly. When one particle carrying energy aa joule collides with another particle carrying energy bb joule, they will be annihilated and produce two new particles carrying the energy of a\\ \\textttAND\\ ba AND b and a\\ \\textttOR\\ ba OR b respectively. Here \\textttANDAND and \\textttOROR mean bitwise AND and OR operation respectively.
The variance of the energy of these particles is obviously not decreasing, but unfortunately, the space here is too small for the author to write down his proof. After enough time the variance of the energy of these particles converges to a stable value. Can you find this value?
The variance of nn numbers is defined as follows.
\\beginaligned \\sigma^2 &= \\frac1n\\sum\\limits_i=1^n(x_i - \\mu)^2 \\ \\textwhere\\ \\mu &= \\frac1n\\sum\\limits_i=1^nx_i \\ \\endaligned
σ
2
where μ
=
n
1
i=1
∑
n
(x
i
−μ)
2
=
n
1
i=1
∑
n
x
i
输入描述:
The first line contains an integer nn (2\\le n\\le 10^52≤n≤10
5
), indicating the number of particles.
The second line contains nn integers a_1,a_2,\\ldots, a_na
1
,a
2
,…,a
n
(0\\le a_i < 2^150≤a
i
<2
15
), indicating the enegery of the particles.
输出描述:
Output a irreducible fraction \\dfracab
b
a
(b > 0b>0) in the form of \\texttta/ba/b that represents the answer. You should ensure that \\gcd(a,b) = 1gcd(a,b)=1 or when a=0a=0, bb should be 11.
示例1
输入
复制
5
1 2 3 4 5
输出
复制
54/5
备注:
Warm tip: Please note the use of data types.
题意:
- 官方:
思路:
- 考虑什么时候稳定。 粒子稳定当且仅当任意操作无意义,即 𝑎,𝑏操作后再次得到 𝑎,𝑏 。不难发现此时必有 𝑎&𝑏=𝑎或者 𝑎&𝑏=𝑏,即任意两数的二进制都有包含关系时稳定。
- 将此时的 𝑎𝑖 从大到小排序,那么每一个位上必为前一半 1 后一半 0 ,否则不满足 𝑎𝑖⊃𝑎𝑖+1的关系。
- 然后求方差即可。本题直接求方差会爆longlong,要么int128,要么用方差期望公式𝐷(𝑥)=𝐸(𝑥^2)−𝐸(𝑥)^2计算。
#include<bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
typedef __int128 LL;
inline __int128 read()
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')if(ch=='-')f=-1;ch=getchar();
while(ch>='0'&&ch<='9')x=x*10+ch-'0';ch=getchar();
return x*f;
inline void print(__int128 x)
if(x<0)putchar('-');x=-x;
if(x>9)print(x/10);
putchar(x%10+'0');
const int maxn = 2e5+10;
LL a[maxn], b[maxn], z[70];
LL gcd(LL a, LL b) return b==0 ? a : gcd(b,a%b);
LL lcm(LL a, LL b) return a/gcd(a,b)*b;
int main()
LL n = read();
LL sum = 0;
for(LL i = 1; i <= n; i++)
LL tmp = read(); sum += tmp;
for(LL j = 63; j >= 0; j--)
if((tmp>>j)&1)z[j]++;
//求粒子稳定后的能量值b数组
int cnt = 0;
while(1)
cnt++;
int ok = 0;
for(LL j = 0; j <= 63; j++)
if(z[j])
b[cnt] += (1<<j);
z[j]--;
ok = 1;
if(ok==0)break;
//求方差x2/y2
LL x2 = 0, y2 = 1;
for(LL i = 1; i <= n; i++)
LL t = b[i]*n-sum; //第i个数x1/y1
LL x1 = t, y1 = n;
t = gcd(x1, y1); x1 /= t; y1 /= t;
x1 *= x1; y1 *= y1;
LL tt = lcm(y1, y2);//累加到答案上
x2 = tt/y1*x1+tt/y2*x2; y2 = tt;
t = gcd(x2, y2); x2 /= t; y2 /= t;
y2 *= n;
LL t = gcd(x2, y2); x2 /= t; y2/=t;
print(x2); cout<<"/"; print(y2); cout<<"\\n";
return 0;
D.Jobs (Easy Version)
Jobs (Easy Version)
比赛主页
团队提交
时间限制:C/C++ 3秒,其他语言6秒
空间限制:C/C++ 524288K,其他语言1048576K
Special Judge, 64bit IO Format: %lld
题目描述
See Problem N for PDF statements.
Note: The only difference between the easy and the hard version is the constraints on nn and m_im
i
.
Since Little Horse gets a golden prize in a programming contest, many companies send offers to him. There are nn companies, and the ii-th company has m_im
i
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 qq 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 IQ, EQ, and AQ of these qq friends are generated as below.
First, register an \\textttmt19937mt19937 random engine \\textttrngrng with the \\textttseedseed and a uniform integer distribution object.
#include
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,q (1 \\le n \\le 101≤n≤10, 1 \\le q \\le 2\\times 10^61≤q≤2×10
6
), indicating the number of companies and Little Horse’s friends.
Then in the next nn lines, the first integer of the ii-th line is m_im
i
(1 \\le m_i \\le 10^51≤m
i
≤10
5
) — the number of jobs in the ii-th company. Then there follow 3m_i3m
i
integers. The jj-th triple integers a_j,b_j,c_ja
j
,b
j
,c
j
(1 \\le a_j,b_j,c_j \\le 4001≤a
j
,b
j
,c
j
≤400) indicate the lower limits of IQ, EQ, and AQ for the jj-th job in the ii-th company.
The next line contains one integer \\textseedseed (10^8\\le \\textseed<2^3110
8
≤seed<2
31
). Then the IQ ,EQ, and AQ of these qq friends are generated as above.
输出描述:
Let’s denote the answer to the ii-th friend as \\textans_ians
i
. You should output:
\\left( \\sum_i=1q\\textans_i\\cdot\\textseedq-i \\right) \\bmod 998244353(∑
i=1
q
ans
i
⋅seed
q−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 55 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 33.
题意:
- 官方:
思路:
- 切入点是能力的数值不超过400,因此可以开出3维的状态,也可以跑出O(n^3)的数据。
考虑每一个工作(a,b,c)我们可以将数组中所有(>a,>b,>c)的位置都打上标记,即可知道第i个公司的某一份工作能否胜任。 - 考虑到10家公司4维的状态开不出来。对于10家公司,采用状态压缩的方式压位,用二进制表示每种工作的出现情况,预处理出三维前缀或,即可O(1)查询每个询问的情况。
- 最后,!!注意题目给的随机数种子,初始化 必须写在输入之后,不然默认都当成0去初始化了,就die了。
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
typedef long long LL;
const LL mod = 998244353;
LL pows(LL a, LL x, LL p) if(x==0)return 1; LL t = pows(a, x>>1, p); if(x%2==0)return t*t%p; return t*t%p*a%p;
int n, q, f[405][405][405];
#include <random>
int solve(int iq, int eq, int aq)
int cnt = 0;
for(int i = 1; i <= n; i++)
if(f[iq][eq][aq]&(1<<i))cnt++;
return cnt;
int main()
IOS;
cin>>n>>q;
for(int i = 1; i <= n; i++)
int k; cin>>k;
for(int j = 1; j <= k; j++)
int iq, eq, aq; cin>>iq>>eq>>aq;
f[iq][eq][aq] |= (1<<i);
for(int i = 1; i <= 400; i++)
for(int j = 1; j <= 400; j++)
for(int k = 1; k <= 400; k++)
f[i][j][k] |= (f[i-1][j][k] | f[i][j-1][k] | f[i][j][k-1]);
int seed; cin>>seed;
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1,400);
int ans = 0;
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
ans = (ans+lastans*pows(seed,q-i,mod)%mod)%mod;
cout<<(ans+mod)%mod<<"\\n";
return 0;
K.NIO’s Sword
链接:https://ac.nowcoder.com/acm/contest/33189/K
来源:牛客网
题目描述
See Problem N for PDF statements.
NIO is playing a new game. In this game, NIO has a sword with attack power represented by an integer AA. Initially, A=0A=0. There are also nn enemies in the game. NIO has to kill them in order, which means NIO must kill the (i-1)(i−1)-th enemy before killing the ii-th enemy for each ii (2\\le i\\le n2≤i≤n). For the ii-th enemy, NIO can kill it if and only if A\\equiv i \\pmodnA≡i(modn).
Fortunately, NIO can upgrade his sword at any moment for any number of times. Each time NIO upgrades his sword, he first chooses an integer xx (0\\le x\\le 90≤x≤9), then changes the attack power of the sword from AA to 10\\times A+x10×A+x.
NIO wants to minimize the number of times to upgrade the sword so that he can win the game as fast as possible. Can you help him to find the minimum times?
输入描述:
The first line contains one integer nn (1\\le n\\le 10^61≤n≤10
6
), indicating the number of enemies.
输出描述:
Output one integer indicating the minimum times to upgrade the sword.
示例1
输入
复制
4
输出
复制
4
说明
Here is a possible solution for the example:
- The attack power of the sword when killing the first enemy can be 10\\times0+1=110×0+1=1.
- The attack power of the sword when killing the second enemy can be 10\\times1+4=1410×1+4=14.
- The attack power of the sword when killing the third enemy can be 10\\times14+7=14710×14+7=147.
- The attack power of the sword when killing the fourth enemy can be 10\\times147+2=147210×147+2=1472.
So he needs to upgrade the sword at least four times.
题意:
- 官方:
思路:
- 官方
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
typedef long long LL;
const LL maxn = 1e6+10, mod = 1e9+7;
LL a[maxn], p[20];
int main()
p[0] = 1; for(int i = 1; i < 8; i++)p[i] = p[i-1]*10;
int n; cin>>n;
if(n==1) cout<<"0\\n"; return 0;
for(int i = 1; i <= n; i++) //为了击杀第i只怪,又进行了ki次升级
for(int k = 1; k < 8; k++) //枚举ki
LL x = (i-(i-1)*p[k]%n+n)%n; //xi = i-(i-1)*10^ki < 10^ki
if(x<p[k])
a[i] = k; break;
LL ans = 0;
for(int i = 1; i <= n; i++)ans += a[i];
cout<<ans<<'\\n';
return 0;
H.Wall Builder II
链接:https://ac.nowcoder.com/acm/contest/33189/H
来源:牛客网
题目描述
See Problem N for PDF statements.
As the builder employed by NIO, you need to build more walls for him. Now you have a number of bricks of height 11 but with different lengths. More precisely, you have nn bricks of length 11, n-1n−1 bricks of length 22, …, two bricks of length n-1n−1, and one brick of length nn. The width of the bricks is negligible. You need to build a wall with these bricks whose shape must be strictly rectangular. When building the wall, you must keep the height of the bricks at 11, which means you cannot rotate them.
Of course, you can definitely build a wall with a height of 11 and a large length, but it is not a beautiful wall. In NIO’s opinion, a beautiful wall should have the minimum possible circumference. Please tell him the minimum circumference of the wall, and how to build it.
输入描述:
The first line contains an integer TT (1 \\le T \\le 1001≤T≤100), indicating the number of test cases.
Each test case contains an integer nn (1 \\le n \\le 1001≤n≤100) in a single line. It is guaranteed that the sum of nn over all test cases won’t exceed 200200.
输出描述:
For each test case, output an integer in a single line, indicating the minimum circumference of the wall. Then in the next \\dfracn(n+1)2
2
n(n+1)
lines, each line contains four integers x_1,y_1,x_2,y_2x
1
,y
1
,x
2
,y
2
, indicating that the coordinate of the lower left of the brick is (x_1,y_1)(x
1
,y
1
), and the upper right is (x_2,y_2)(x
2
,y
2
).
You can consider the wall as a rectangular in the Cartesian coordinate system, where the xx-axis represents the length and the yy-axis represents the height. The lower left of the wall must be located at (0,0)(0,0). If there are multiple solutions, output any.
示例1
输入
复制
4
1
2
3
4
输出
复制
4
0 0 1 1
8
0 1 1 2
1 1 2 2
0 0 2 1
14
2 1 3 2
3 1 4 2
4 1 5 2
3 0 5 1
0 1 2 2
0 0 3 1
18
4 0 5 1
2 3 3 4
3 3 4 4
4 3 5 4
3 1 5 2
3 2 5 3
0 3 2 4
0 1 3 2
0 2 3 3
0 0 4 1
说明
A possible solution for the third test case in the sample:
题意:
- 官方:
思路:
- 官方:
#include<bits/stdc++.h>
using namespace std;
int cur[1200];//当前第i行的长度
vector<pair<int, int> >ans[120];
int check(int n, int h, int w) //验证对于n能否拼出h*w的矩形
for(int i = 0; i < h; i++)cur[i] = 0;
for(int i = n; i >= 1; i--) //矩形的长度,从长到短放入第k行
ans[i].clear();
int cnt = n-i+1; //1个1*n,2个1*n-1,...,n-1个1*2,n个1*1的矩形
for(int j = 0; j < cnt; j++)
int ok = 0;
for(int k = 0; k < h; k++)
if(cur[k]+i<=w) //能放就放进去
ans[i].push_back(k,cur[k]);//长度i:第k行,左下角cur[k]
cur[k] += i;
ok = 1;
break;
if(!ok)return 0; //每一行都放不进去,那就再见
cout<<2*(h+w)<<"\\n";
for(int i = 1; i <= n; i++)
for(int j = 0; j < n-i+1; j++)
cout<<ans[i][j].second<<" "<<ans[i][j].first<<' '<<ans[i][j].second+i<<" "<<ans[i][j].first+1<<"\\n";
以上是关于“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL的主要内容,如果未能解决你的问题,请参考以下文章