当前位置:网站首页>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;
}
边栏推荐
- Redis:哈希hash类型数据操作命令
- Select function variable column name in dplyr of R language
- 分布式CAP理论
- Experience sharing of epidemic telecommuting | community essay solicitation
- I.MX6U-ALPHA开发板(模仿STM32驱动开发实验)
- [Yugong series] go teaching course 002 go language environment installation in July 2022
- 戳气球和布尔运算问题(巨难)
- 浅谈JVM的那些事
- [wechat applet] good looking carousel map component
- (指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
猜你喜欢
Rhcsa 04 - process management
The five pictures tell you: why is there such a big gap between people in the workplace?
tdk-lambda电源主要应用
Kivy教程之 更改背景颜色(教程含源码)
Longest increasing subsequence problem (do you really know it)
Formatted text of Kivy tutorial (tutorial includes source code)
旭化成首次参展第五届中国国际进口博览会(5th CIIE)
【安全攻防】序列化与反序列,你了解多少?
Architecture practice camp - graduation project of module 9 of phase 6
资深开发人员告诉你,怎样编写出优秀的代码?
随机推荐
Main applications of TDK lambda power supply
Architecture practice camp - graduation project of module 9 of phase 6
y55.第三章 Kubernetes从入门到精通 -- HPA控制器及metrics-server(二八)
[wechat applet] good looking carousel map component
R语言中如何查看已安装的R包
Asynchronous development process - touch your hand and lead you to realize a promise
MIN_ RTO dialog
Network - vxlan
AcWing第 58 场周赛
RPC Technology
苹果CMS仿西瓜视频大气响应式视频模板源码
(指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
Leetcode 121 best time to buy and sell stock (simple)
Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
EventBridge 在 SaaS 企业集成领域的探索与实践
[Yugong series] go teaching course 002 go language environment installation in July 2022
6-4漏洞利用-SSH Banner信息获取
The five pictures tell you: why is there such a big gap between people in the workplace?
Talking about what a high-quality little red book copy needs to have