当前位置:网站首页>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;
}
边栏推荐
- 优秀的测试/开发程序员是怎么修炼的?该往哪走......
- Emlog用户注册插件 价值80元
- What is context?
- Leetcode brush questions: binary tree 05 (flip binary tree)
- 虚拟商品帐号交易平台源码_支持个人二维码收款
- Asahi Kasei participated in the 5th China International Import Expo (5th ciie) for the first time
- Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
- FT2000+下LPC中断绑核使用说明
- Kivy教程之 格式化文本 (教程含源码)
- [microservices openfeign] two degradation methods of feign | fallback | fallbackfactory
猜你喜欢
Imitation of "game bird" source code, mobile game issue evaluation, open service, open test collection, game download website template
Kivy教程之 更改背景颜色(教程含源码)
How to view installed r packages in R language
96% of the collected traffic is prevented by bubble mart of cloud hosting
【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
[wechat applet] good looking carousel map component
统计遗传学:第三章,群体遗传
Redis: hash type data operation command
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Graduation project
随机推荐
Imitation of "game bird" source code, mobile game issue evaluation, open service, open test collection, game download website template
First knowledge of batch processing
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
微信公众号无限回调授权系统源码
虚拟商品帐号交易平台源码_支持个人二维码收款
两万字带你掌握多线程
Kivy tutorial custom fonts (tutorial with source code)
Leetcode skimming: binary tree 07 (maximum depth of binary tree)
Apple CMS imitation watermelon video atmospheric response video template source code
The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
Precautions for accompanying driving these 23 points should be paid attention to!
Rhcsa 06 - suid, sgid, sticky bit (to be added)
Leetcode brush question: binary tree 06 (symmetric binary tree)
Formatted text of Kivy tutorial (tutorial includes source code)
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
R语言dplyr中的Select函数变量列名
Dp83848+ network cable hot plug
Redis:集合Set类型数据的操作命令
[microservice openfeign] @feignclient detailed explanation
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence