当前位置:网站首页>Niuke Xiaobai monthly race 49
Niuke Xiaobai monthly race 49
2022-07-04 04:36:00 【Changersh】
A
Sign in
After reading the string , Convert bits into numbers ,%3 Output
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include<unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 1e4 + 5;
const int MOD = 1e9 + 7;
char s[3], t[3];
int main() {
scanf("%s %s", s, t);
int a = s[0] - '0' + t[0] - '0';
a %= 3;
int b = s[1] - '0' + t[1] - '0';
b %= 3;
int c = s[2] - '0' + t[2] - '0';
c %= 3;
printf("%d%d%d", a, b, c);
return 0;
}
B
simulation
Now look , I feel it's troublesome to write
use s The array stores the gifts received and the corresponding colors ( Write too much , It leads to direct search , A waste of time , Should be assigned directly , Find it like this O(1))
Then I didn't input a color , Just judge once
Because color judgment is cumulative , It means that the last thing we input is 3 2 1 , Judge the first 3 when , Just find a gift with three , Judge the second 2 When , To statistics meanwhile There are color 3 and 2 A gift from
If a gift is in a certain color judgment , Not meeting the conditions , Just take the first one of the gift colors The assignment is 1, When traversing, judge whether to skip
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include<unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 205;
const int MOD = 1e9 + 7;
int n, m;
int s[N][N];
void solve() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &s[i][j]);
}
}
int a, cnt = 0;
for (int i = 0; i < m; i++) {
scanf("%d", &a);
for (int j = 0; j < n; j++) {
bool flag = false;
for (int k = 0; k < m; k++) {
if (s[j][0] == -1) break;
if (s[j][k] == a) {
cnt++, flag = true;
break;
}
}
if (flag == false) s[j][0] = -1;
}
printf("%d ", cnt);
cnt = 0;
}
printf("\n");
}
int main() {
int T;
scanf("%d", &T);
while (T--)
solve();
return 0;
}
Bucket row
vis[], The first i Item , Contains color …, This is a direct assignment ,O(1) lookup
judge[] It's No i Is the gift still qualified
b[] Receive the color to find
First traverse the color , Inner traversal gift , Judge gifts one by one , If b The color of the array , This gift has , And also meet the conditions , Just ans++
otherwise judge = 1, It means that the conditions are not met , After traversing a color, output it
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include<unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 205;
const ll MOD = 1e9 + 7;
int n, m, a;
int vis[N][N]; // The first i Pieces of goods contain Color j
int judge[N]; // The first i Pieces of goods Whether the conditions are still met
int b[N];
void solve() {
memset(vis, 0, sizeof(vis));
memset(judge, 0, sizeof(judge));
memset(b, 0, sizeof(b));
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
scanf("%d", &a);
vis[i][a] = 1; // The first i Item , There are color a
}
for (int i = 0; i < m; i++) scanf("%d", &b[i]);
for (int j = 0; j < m; j++) {
int ans = 0;
for (int i = 0; i < n; i++) {
if (vis[i][b[j]]) {
if (!judge[i]) ans++;
}
else {
judge[i] = 1;
}
}
printf("%d%c", ans, (j == m - 1) ? '\n' : ' ');
}
}
int main() {
int T;
scanf("%d", &T);
while (T--)
solve();
return 0;
}
C
An operation + thinking
ai & aj ,& There are only two corresponding positions yes 1 When it comes to 1, therefore ,& The operation can only be original 1 The quantity remains the same , Or reduce , It's impossible to increase , therefore & The subsequent value must be less than or equal to ai and aj Of , And it is smaller than the smaller one of them
And then there is ,| operation , In fact Add 1 The operation of , Because one must be ai & ai Of , The result is ai, Everything else & value , It must be less than or equal to ai Of , all ai | Other values , The result is ai
therefore The final result is actually hold a1~an All the values XOR up
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include<unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 5e5 + 5;
const int MOD = 1e9 + 7;
int n, a[N];
long long res = 0;
void solve() {
scanf("%d", &n);
res = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
res ^= a[i];
}
printf("%lld\n", res);
}
int main() {
int T;
scanf("%d", &T);
while (T--)
solve();
return 0;
}
D
Quadratic function image + Inverse element
From the quadratic function image, we can get , The maximum value is actually greater than 0 Part of ,S(b) - S(a)
Then cut off the quadratic function , Find the sum of each term separately , And then add it up
Inverse element part , Generally, there are pits in division , There are decimals in division , But it's divisible , I made an appointment , The title does not say that it is a downward division , So divide —> Multiplication , Using the inverse element
Topic mod + 1 Then it happens to be divisible 2 and 6 Of , So you can write conveniently
iv2 = (MOD + 1) / 2ll;
iv6 = (MOD + 1) / 6ll;
Remember to take the mold ,ans and Output S(b) - S(a)
Sure add MOD Then take the mold , Prevent overflow ;
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include<unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
const int N = 1e4 + 5;
const ll MOD = 998244353;
const ll iv2 = (MOD + 1) / 2ll;
const ll iv6 = (MOD + 1) / 6ll;
ll a, b;
ll S(int t) {
ll ans1 = t * (t + 1ll) % MOD * (2ll * t + 1ll) % MOD * iv6 % MOD;
ll ans2 = (a + b) * t % MOD * (t + 1ll) % MOD * iv2 % MOD;
ll ans3 = a * b % MOD * t % MOD;
ll ans = -ans1 + ans2 - ans3;
ans = (ans % MOD + MOD) % MOD;
return ans;
}
void solve() {
scanf("%lld%lld", &a, &b);
printf("%lld\n", (S(b) - S(a) + MOD) % MOD);
}
int main() {
int T;
scanf("%d", &T);
while (T--)
solve();
return 0;
}
边栏推荐
- Formatted text of Kivy tutorial (tutorial includes source code)
- 架构训练毕业设计+总结
- 领导:谁再用redis过期监听实现关闭订单,立马滚蛋!
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- How to add custom API objects in kubernetes (1)
- Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)
- Why use node
- UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
- Distributed cap theory
- Dp83848+ network cable hot plug
猜你喜欢
FT2000+下LPC中断绑核使用说明
Tcp- simple understanding of three handshakes and four waves
[microservice openfeign] @feignclient detailed explanation
疫情远程办公经验分享| 社区征文
Keysight n9320b RF spectrum analyzer solves tire pressure monitoring scheme
R语言中如何查看已安装的R包
Experience sharing of epidemic telecommuting | community essay solicitation
Main applications of TDK lambda power supply
Exploration and practice of eventbridge in the field of SaaS enterprise integration
[Yugong series] go teaching course 001 in July 2022 - Introduction to go language premise
随机推荐
y55.第三章 Kubernetes从入门到精通 -- HPA控制器及metrics-server(二八)
tdk-lambda电源主要应用
Redis:哈希hash类型数据操作命令
疫情远程办公经验分享| 社区征文
RHCSA 08 - automount配置
新手找陪驾要注意什么
Pytest basic self-study series (I)
What does software testing do? Find defects and improve the quality of software
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
Redis:集合Set类型数据的操作命令
Many founders of technology companies provided enterpriser first with a round C financing of up to US $158million to help it invest in the next generation of global innovators
Dp83848+ network cable hot plug
Emlog用户注册插件 价值80元
Architecture practice camp - graduation project of module 9 of phase 6
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
Deep parsing structured exception handling (SEH) - by Matt Pietrek
Cmake compilation option setting in ros2
RPC Technology
什么是上下文?
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线