当前位置:网站首页>2018HBCPC部分题解
2018HBCPC部分题解
2022-08-06 03:26:00 【蜡笔小金QAQ】
2018HBCPC部分题解
Mex Query

#include <bits/stdc++.h>
using namespace std;
// 传送门:http://newoj.acmclub.cn/problems/2011
int T;
int n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--)
{
set<int> s;
cin >> n;
for (int i = 1; i <= n; i++)
{
int remp;
cin >> remp;
s.insert(remp);
}
set<int>::iterator it;
int cont = 0;
for (it = s.begin(); it != s.end(); it++)
{
if (*it != cont)
{
cout << cont << endl;
break;
}
cont++;
}
}
return 0;
}
icebound的商店


#include <bits/stdc++.h>
using namespace std;
// http://newoj.acmclub.cn/problems/2012
// 完全背包
#define mod 1000000009
int bag[15];
int ans[3010];
int T;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
bag[1] = 1;
bag[2] = 2;
for (int i = 3; i <= 15; i++)
bag[i] = bag[i - 1] + bag[i - 2];
ans[0] = 1;
for (int i = 1; i <= 15; i++)
{
for (int j = bag[i]; j <= 3010; j++)
{
ans[j] += ans[j - bag[i]];
ans[j] %= mod;
}
}
cin >> T;
for (int i = 1; i <= T; i++)
{
int tar;
cin >> tar;
cout << ans[tar] << endl;
}
return 0;
}
Nim Game



#include <bits/stdc++.h>
using namespace std;
// 博弈论:Nim
// http://newoj.acmclub.cn/problems/2013
const int MOD = 1e9 + 7;
int T;
int n, m;
int a[1000100];
int sum[1000100];
int f[1000100];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--)
{
cin >> n >> m;
memset(sum, 0, sizeof(sum));
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum[i] = sum[i - 1] ^ a[i];
}
for (int i = 1; i <= m; i++)
{
int l, r;
cin >> l >> r;
int result = sum[r] ^ sum[l - 1]; //第i次结果
if (result)
f[i] = 1;
else
f[i] = 0;
}
long long ans = 0;
for (int i = 1; i <= m; i++)
{
ans = ans << 1;
ans += f[i];
ans = ans % MOD;
}
cout << ans << endl;
}
return 0;
}
神殿


#include <bits/stdc++.h>
using namespace std;
// http://newoj.acmclub.cn/problems/2016
long long l, r;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> l >> r;
while (l <= r)
{
if ((l | l + 1) > r) //(l | l + 1)为的是将l的最低一位0尝试改成1
break;
l = (l | l + 1);
}
cout << l << endl;
return 0;
}
跑图

TLE解法
#include <bits/stdc++.h>
using namespace std;
// TLE解法。。。
int n, m;
int graph[510][510];
int ans[510][510];
int cnt;
struct node
{
int x, y;
} point[250010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
memset(ans, 0x3f, sizeof(ans));
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
cin >> graph[i][j];
if (graph[i][j])
{
++cnt;
point[cnt].x = i;
point[cnt].y = j;
}
}
for (int k = 1; k <= cnt; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (graph[i][j])
ans[i][j] = 0;
else
ans[i][j] = min(ans[i][j], abs(point[k].x - i) + abs(point[k].y - j));
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cout << ans[i][j];
if (j != m)
cout << " ";
}
cout << endl;
}
return 0;
}
正解
#include <bits/stdc++.h>
using namespace std;
// http://newoj.acmclub.cn/problems/2018
// 正解:BFS
int n, m;
int graph[510][510];
bool visit[510][510];
int ans[510][510];
int dirx[] = {
0, 0, -1, 1};
int diry[] = {
1, -1, 0, 0};
struct node
{
int x, y;
};
queue<node> q;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> graph[i][j];
if (graph[i][j])
{
node remp;
remp.x = i, remp.y = j;
visit[i][j] = true;
q.push(remp);
}
}
}
while (q.empty() == false)
{
node remp = q.front();
int rempx = remp.x, rempy = remp.y;
q.pop();
for (int i = 0; i < 4; i++)
{
int nextx = rempx + dirx[i];
int nexty = rempy + diry[i];
if (visit[nextx][nexty] == false && (nextx <= n && nextx >= 1 && nexty <= m && nexty >= 1))
{
ans[nextx][nexty] = ans[rempx][rempy] + 1;
visit[nextx][nexty] = true; //易错点!!一定要第一次更新完就马上标记!因为此时不标记,后面可能被二次标记,这时候就不是最近的了
node next;
next.x = nextx, next.y = nexty;
q.push(next);
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cout << ans[i][j];
if (j != m)
cout << " ";
}
cout << endl;
}
return 0;
}
520

#include <bits/stdc++.h>
using namespace std;
// 快速幂
#define MOD 20180520
long long fast_power(long long a, long long b, long long c)
{
long long ans = 1;
a = a % c;
while (b)
{
if (b % 2)
ans = (ans * a) % c;
b /= 2;
a = (a * a) % c;
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
long long n;
cin >> n;
cout << fast_power(2, n, MOD);
return 0;
}
icebound的账单

边栏推荐
- FluentValidation
- 浦发银行长沙分行党委书记、行长王起,华融湘江银行行长蒋俊文一行莅临麒麟信安调研考察
- leetcode:1374. Generate an odd number of each character string
- If you like us, it is better to join us: come and contribute, the payment is reliable!
- Redis Cluster的部署与维护
- 造自己的芯,让谷歌买单!谷歌再度开源 180nm 工艺的芯片
- Advantages and disadvantages of solid tires
- sql server, two tables, the same field, the same amount of data (50 million), execute the same query, one table executes an index scan, scanning 50 million, which takes 2 minutes, the other table exec
- 实心轮胎的优缺点
- The delivery language set in the Google Ads background, if English is set, does it mean that the user is using English?
猜你喜欢

喜欢我们不如加入我们:来投稿吧,稿酬靠谱!

leetcode 15. Sum of three numbers
![[Deep Learning 21 Days Learning Challenge] Memo: Model Reuse - Model Saving and Loading](/img/1d/3b076809692c81c5446a3a93d8fdfd.png)
[Deep Learning 21 Days Learning Challenge] Memo: Model Reuse - Model Saving and Loading

加密熊市为企业并购提供机遇 野心勃勃or救世主?唯一真理便是利益至上

Wang Qi, Secretary of the Party Committee and President of Shanghai Pudong Development Bank Changsha Branch, and Jiang Junwen, President of Huarong Xiangjiang Bank, visited Kylin Principal for investi

xctf attack and defense world web master advanced area command_execution

Mysql installation ask for answers

R语言ggplot2循环中保存图片失败问题

详解 类和对象

Mysql安装 求大拿解答
随机推荐
Fragment的四种跳转方式
What are the highlights of the 2022 Jingdong New Department Store Qixi Festival Promotion Season?
【翻译】无服务器架构:利与弊
什么是固体充气轮胎(solid pneumatic tyres)?
If a country's market effect is particularly good, how can we increase the proportion of this country's investment?
pytest之assert断言的使用
6. -- -- -- -- -- test automation of software testing unittest framework
网络安全辅助工具:免费MD5解密网站
Use BeanUtils with caution, the performance really stretches!
慎用BeanUtils,性能真的拉跨!
xctf攻防世界 Web高手进阶区 easytornado
FluentValidation
2022年天猫8月份有什么大的活动?
Sring中常用注解归纳
2022 使用Go语言构建现代 Web 应用程序实战内容课程
The second day of learning MySQL: SQL (basic)
运维小白成长记——架构第10周
数字化智能工厂解决方案47页
firewall and ufw notes
什么浏览器广告少?多御安全浏览器轻体验