当前位置:网站首页>“蔚来杯“2022牛客暑期多校训练营4 DHKLN
“蔚来杯“2022牛客暑期多校训练营4 DHKLN
2022-07-30 22:47:00 【HeartFireY】
D.Jobs (Easy Version)
题目大意
三维偏序问题,队友写了个假做法过了。
待补
Code
#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
//#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10, MOD = 998244353;
int n, q, x, y, z;
int k1,k2,k3,k4;
bitset<402>fk[11][401][401];
inline int getid(int x,int y,int z){
return 160801*(x)+(y)*(401)+z;
}
int getans(int iq, int eq, int aq){
int ans=0;
for(int i=1;i<=n;i++){
ans+=fk[i][iq][eq][aq];
}
return ans;
}
int binpow(long long x, int y, int mod, long long res = 1){
for (; y; y >>= 1, (x *= x) %= mod) if (y & 1) (res *= x) %= mod;
return res;
}
int powq[2000010];
inline void solve(){
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> k1;
for(int j = 1; j <= k1; j++) {
cin>>x>>y>>z;
fk[i][x][y][z]=1;
}
}
for(short i=1;i<=n;i++){
for(short j=1;j<=400;j++){
for(short k=1;k<=400;k++){
for(short x=1;x<=400;x++){
fk[i][j][k][x]=fk[i][j][k][x]|fk[i][j][k][x-1]|fk[i][j][k-1][x]|fk[i][j-1][k][x];
}
}
}
}
int seed; cin >> seed;
powq[0] = 1;
for(int i = 1; i <= 2000000 + 5; i++){
powq[i] = 1ll * powq[i - 1] * seed % MOD;
}
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1, 400);
int lastans = 0, ans = 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 = getans(IQ, EQ, AQ); // The answer to the i-th friends
(ans += (1ll * lastans * powq[q - i] % MOD)) %= MOD;
}
cout << (ans % MOD) << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1;
while(t--) solve();
return 0;
}
H.Wall Builder II
题目大意
给 n n n个 1 ∗ 1 1*1 1∗1的矩形, n − 1 n-1 n−1个 1 ∗ 2 1*2 1∗2的矩形, n − 2 n-2 n−2个 1 ∗ 3 1*3 1∗3的矩形…, 1 1 1个 1 ∗ n 1*n 1∗n的矩形,把这些矩形拼成一个大矩形,求大矩形的最小周长。
从 s \sqrt{s} s开始枚举,然后找到第一个能凑的矩形并贪心填充即可。
Code
#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e4 + 10, MOD = 1e9 + 7;
int row[N];
inline void solve(){
int n = 0, s = 0; cin >> n;
memset(row, 0, sizeof(row));
for(int i = 1; i <= n; i++) s += (n - i + 1) * i;
for(int w = sqrt(s); w <= s; w++){
if(s % w) continue;
int h = s / w;
cout << (h + w) * 2 << endl;
for(int i = n; i >= 1; --i){
for(int j = 1, id = 0; j <= n - i + 1;){
if(row[id] + i <= w){
cout << row[id] << ' ' << id << ' ' << row[id] + i << ' ' << id + 1 << endl;
row[id]+= i, j++;
}
else id++;
}
}
break;
}
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1; cin >> t;
while(t--) solve();
return 0;
}
K.NIO’s Sword
题目大意
玩家初始有一把攻击力为 0 0 0的剑,需要依次击杀 n n n个敌人,仅当攻击力模 n n n与 i i i同余才能击杀第 i i i个敌人。玩家可以升级剑,每次升级相当于在当前攻击力后面添加一个数字,问最少需要几次升级。
对每个 i i i,枚举 k i k_i ki,计算 x i x_i xi,判断是否满足即可。
Code
#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10, MOD = 1e9 + 7;
int f[10];
inline void solve(){
int n; cin >> n;
int ans = 0;
f[0] = 1;
for(int i = 1; i < 8; ++i) f[i] = f[i - 1] * 10;
if(n == 1){
cout << "0\n";
return;
}
for(int i = 1; i <= n; ++i){
int tmp = i - 1;
for(int j = 1; j <= 7; ++j){
if(((i - tmp * f[j]) % n + n) % n < f[j]){
ans += j;
break;
}
}
}
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
L.Black Hole
题目大意
给定正 n n n面体(不一定合法,不合法就impossible),边长为 a a a,进行 k k k次操作,每次操作取正多面体几何中心连线生成新凸壳。问 K K K次操作后生成的是否为正多面体,以及最终正多面体的边长。
首先,合法的正多面体只有:正四面体、正六面体、正八面体、正十二面体、正二十面体。
- 正四面体只能生成正四面体
- 正六面体操作奇数次可以生成正八面体,偶数次生成正六面体
- 正八面体操作奇数次可以生成正六面体,偶数次生成正八面体
- 正十二面体操作奇数次可以生成正二十面体,偶数次生成正十二面体
- 正二十面体操作奇数次可以生成正十二面体,偶数次生成正二十面体
接下来讨论边长变化规律:可以发现两次生成的边长关系可以由原体的内切球和生成体的外接球关系导出,因为这俩球是同一个球。那么首先我们整理一下边长 a a a与球半径 r r r关系公式:
| 正四面体 | 正六面体 | 正八面体 | 正十二面体 | 正二十面体 | |
|---|---|---|---|---|---|
| 内切球 | r a = 6 12 \frac{r}{a} = \frac{\sqrt{6}}{12} ar=126 | r a = 1 2 \frac{r}{a} = \frac{1}{2} ar=21 | r a = 6 6 \frac{r}{a} = \frac{\sqrt{6}}{6} ar=66 | r a = φ 2 2 3 − φ \frac{r}{a} = \frac{\varphi^2}{2\sqrt{3 - \varphi}} ar=23−φφ2 | r a = 3 3 + 15 12 \frac{r}{a} = \frac{3\sqrt{3} + \sqrt{15}}{12} ar=1233+15 |
| 外接球 | r a = 6 4 \frac{r}{a} = \frac{\sqrt{6}}{4} ar=46 | r a = 3 2 \frac{r}{a} = \frac{\sqrt{3}}{2} ar=23 | r a = 2 2 \frac{r}{a} = \frac{\sqrt{2}}{2} ar=22 | r a = 3 φ 2 \frac{r}{a} = \frac{\sqrt{3} \varphi}{2} ar=23φ | r a = 10 + 2 5 4 \frac{r}{a} = \frac{\sqrt{10 + 2\sqrt{5}}}{4} ar=410+25 |
那么我们可以推出转换关系:
- 正四面体 → \rightarrow →正四面体: a 2 a 1 = 1 3 \frac{a_2}{a_1} = \frac{1}{3} a1a2=31
- 正六面体 → \rightarrow →正八面体: a 2 a 1 = 1 2 \frac{a_2}{a_1} = \frac{1}{\sqrt{2}} a1a2=21
- 正八面体 → \rightarrow →正六面体: a 2 a 1 = 2 3 \frac{a_2}{a_1} = \frac{\sqrt{2}}{3} a1a2=32
- 正十二面体 → \rightarrow →正二十面体: a 2 a 1 = φ 2 3 − φ × 2 5 + 10 \frac{a_2}{a_1} = \frac{\varphi^2}{\sqrt{3 - \varphi} \times \sqrt{2 \sqrt{5} + 10}} a1a2=3−φ×25+10φ2
- 正二十面体 → \rightarrow →正十二面体: a 2 a 1 = 5 + 3 6 φ \frac{a_2}{a_1} = \frac{\sqrt{5} + 3}{6 \varphi} a1a2=6φ5+3
至此,可以通过递推得到答案。
Code
#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
#define int long long
#define double long double
#define endl '\n'
using namespace std;
const int N = 2e5 + 10, MOD = 1e9 + 7;
double K[20];
int nxt[20], n, k;
double a;
void init(){
cout << fixed << setprecision(12);
K[4] = 1.0 / 3;
double fi = (1 + sqrtl(5)) / 2;
K[6] = sqrtl(2) / 2;
K[8] = sqrtl(2) / 3;
K[12] = 2 * fi / sqrtl(3 - fi) * fi / sqrtl(10 + 2 * sqrtl(5));
K[20] = (3 + sqrtl(5)) / 6 / fi;
nxt[4] = 4, nxt[6] = 8, nxt[8] = 6, nxt[12] = 20, nxt[20] = 12;
}
inline void solve(){
cin >> n >> a >> k;
if(n != 4 && n != 6 && n != 8 && n != 12 && n != 20){
cout << "impossible\n";
return;
}
for(int i = 1; i <= k; i++){
a *= K[n], n = nxt[n];
}
cout << "possible "<<n<<" "<<a<<endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
init();
int t = 1; cin >> t;
while(t--) solve();
return 0;
}
N.Particle Arts
题目大意
给定序列 a 1 , a 2 , … , a n a_1, a_2, \dots, a_n a1,a2,…,an,每当两个元素 a a a和 b b b相撞后会湮灭并产生两个新元素 a & b a \& b a&b和 a ∣ b a | b a∣b。若干次碰撞后,方差会收敛。求收敛后的方差。
首先可以发现,任意两个元素相撞变化后,不会引起总和的变化,因此均值是不变的。
那么考虑求经过无限此碰撞后生成的新序列,容易发现因为或操作的性质,二进制下为 1 1 1的位不会消失,那么无限次或操作会将为 1 1 1的位向同一数字靠拢。于是直接按位统计后生成新序列计算即可。
如果使用公式 E ( x 2 ) − E 2 ( x ) E(x^2) - E^2(x) E(x2)−E2(x),需要继续推式子;但可以直接怼上方差公式,但是又会爆long long,那么可以在运算过程中全部使用__int128计算,最后转long long输出。
Code
#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
#define int __int128
#define endl '\n'
using namespace std;
const int N = 2e5 + 10, MOD = 1e9 + 7;
long long a[N], b[N], cnt[20];
inline void solve(){
long long n = 0, sum = 0; cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
int cnt0 = 0, cnt1 = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < 15; j++){
if((a[i] >> j) & 1) cnt[j]++;
}
}
for(int i = 0; i < 15; i++){
for(int j = 1; j <= cnt[i]; j++) b[j] |= (1 << i);
}
int f1 = 0;
for(int i = 1; i <= n; i++){
f1 += (n * b[i] - sum) * (n * b[i] - sum);
}
int f2 = n * n * n;
int gcdd = __gcd(f1, f2);
//cout << f1 << '@' << f2 << endl;
long long ans1 = f1 / gcdd, ans2 = f2 / gcdd;
//cout << (f1 / gcdd) << '/' << (f2 / gcdd) << endl;
cout << ans1 << '/' << ans2 << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
边栏推荐
- MySQL进阶sql性能分析
- cmd(命令行)操作或连接mysql数据库,以及创建数据库与表
- 解决一个Mysql的utf8编码导致的问题
- MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
- Learning about XML (1)
- Golang 切片删除指定元素的几种方法
- 【无标题】
- MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
- "Code execution cannot continue because MSVCP140.dll was not found, reinstalling the program may resolve the problem, etc." Solutions
- Successfully resolved ModuleNotFoundError: No module named 'Image'
猜你喜欢

QT 在父类中添加子类的流程,object tree,

【2022-05-31】JS逆向之易企秀

抽象类和接口(学习笔记)

482-静态库、动态库的制作、使用及区别

Apache Doris系列之:安装与部署详细步骤

Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)

MySQL索引常见面试题(2022版)

Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言

When Navicat connects to MySQL, it pops up: 1045: Access denied for user 'root'@'localhost'

Navicat cannot connect to mysql super detailed processing method
随机推荐
Go语学习笔记 - gorm使用 - 表增删改查 Web框架Gin(八)
2022.7.27
vulnhub靶机AI-Web-1.0渗透笔记
It is enough for MySQL to have this article (disgusting typing 37k words, just for Bojun!!!)
Achievements of Science and Technology (31)
Chapter 8 Intermediate Shell Tools II
Abstract classes and interfaces (study notes)
编码与进制
cnpm的安装与使用
打动中产精英群体,全新红旗H5用产品力跑赢需求
mysql锁机制
1064 Complete Binary Search Tree
Difference between cookie and session
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
2022/07/30 学习笔记 (day20) 面试题积累
Compressing Deep Graph Neural Networks via Adversarial Knowledge Distillation
Successfully resolved ModuleNotFoundError: No module named 'Image'
d使用among的问题
mysql remove duplicate data
解决一个Mysql的utf8编码导致的问题