C.Cypher Decypher

题意

找 [ i , j ] [i,j] [i,j]区间中有多少个质数

思路

数据范围为 1 ≤ i ≤ j ≤ 1 0 6 1\le i\le j\le 10^6 1≤i≤j≤106
直接素数筛+前缀和即可

代码

/** @Author: Icey_dying* @Date: 2021-10-02 15:02:33* @LastEditors: Icey_dying* @LastEditTime: 2021-10-02 15:09:02* @FilePath: \Icey_dying\competition\2021\2021.10\2021.10.2\C.cpp*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int prime[N], b[N];
int cnt = 0, max1 = 1e6;
int init()
{memset(b, 0, sizeof(b));b[0] = b[1] = 1;for (int i = 2; i <= max1; i++) {if (!b[i])prime[++cnt] = i;for (int j = 1; j <= cnt && prime[j] * i <= max1; j++) {b[prime[j] * i] = 1;if (i % prime[j] == 0)break;}}return 0;
}
int a[1000005];
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t;init();memset(a, 0, sizeof(a));for (int i = 1; i <= max1; i++)a[i] = a[i - 1] + !(b[i]);cin >> t;int i, j;while (t--) {cin >> i >> j;cout << a[j] - a[i - 1] << endl;}return 0;
}

E.Escape Room

题意

地图上有物体,墙,人和出口,现在问你坐标上是否有东西,如果有则输出相应的,如果没有输出如何最快到达出口的方向

思路

从出口BFS即可,注意题目中上左下右有先后顺序,找完之后记得看看有没有更优先的方向

代码

/** @Author: Icey_dying* @Date: 2021-10-04 10:58:31* @LastEditors: Icey_dying* @LastEditTime: 2021-10-04 11:11:05* @FilePath: \Icey_dying\competition\2021\2021.10\2021.10.2\E.cpp*/
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
char a[N][N], s[N];
int n, m, f[N][N], v[N][N];
int dx[] = { 0, 0, -1, 0, 1 }, dy[] = { 0, 1, 0, -1, 0 };
queue<int> qx, qy;
int x, y, q;
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> n >> m;for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)a[i][j] = '#';for (int i = 1; i <= n; i++) {cin >> a[i] + 1;a[i][m + 1] = '#';}memset(f, 0x3f, sizeof(f));for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++) {if (a[i][j] == 'E') {f[i][j] = 0;qx.push(i);qy.push(j);}}}while (qx.size()) {x = qx.front();qx.pop();y = qy.front();qy.pop();for (int i = 1; i <= 4; i++) {if (a[x + dx[i]][y + dy[i]] == 'X' || a[x + dx[i]][y + dy[i]] == '#')continue;if (f[x + dx[i]][y + dy[i]] > f[x][y] + 1) {f[x + dx[i]][y + dy[i]] = f[x][y] + 1;v[x + dx[i]][y + dy[i]] = i;qx.push(x + dx[i]);qy.push(y + dy[i]);}}}for (int i = 1; i <= n; i++) {for (int j = 1; j <= m; j++) {for (int k = 1; k <= 4; k++) {if (f[i][j] + 1 == f[i + dx[k]][j + dy[k]] && v[i + dx[k]][j + dy[k]] > k) {v[i + dx[k]][j + dy[k]] = k;}}}}cin >> q;while (q--) {cin >> x >> y;if (a[x][y] == '#')cout << "W\n";else if (a[x][y] == 'X')cout << "X\n";else if (a[x][y] == 'E')cout << "E\n";else if (f[x][y] == f[0][0])cout << "?\n";else {if (v[x][y] == 1)cout << "L\n";else if (v[x][y] == 2)cout << "D\n";else if (v[x][y] == 3)cout << "R\n";elsecout << "U\n";}}return 0;
}

F.Fixing Subtitles

题意

字幕有延迟,先给出原本的字幕时间和字幕本身和延迟时间,让你输出字幕的正确时间和字幕

思路

这道题只有输入输出麻烦,时间的转换是比较简单的,慢慢调试即可

代码

/** @Author: Icey_dying* @Date: 2021-10-02 15:31:31* @LastEditors: Icey_dying* @LastEditTime: 2021-10-02 16:04:50* @FilePath: \Icey_dying\competition\2021\2021.10\2021.10.2\F.cpp*/
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
void f(int& h, int& m, int& s, int& ms)
{ms += y;s += x + ms / 1000;ms %= 1000;m += s / 60;s %= 60;h += m / 60;m %= 60;
}
int h, m, s, ms, now;
string st;
int main()
{scanf("%d %d.%d", &n, &x, &y);for (int i = 1; i <= n; i++) {scanf("%d", &now);printf("%d\n", now);scanf("%d:%d:%d,%d", &h, &m, &s, &ms);f(h, m, s, ms);printf("%02d:%02d:%02d,%03d", h, m, s, ms);scanf(" --> %d:%d:%d,%d", &h, &m, &s, &ms);//cout << ms << endl;f(h, m, s, ms);printf(" --> %02d:%02d:%02d,%03d\n", h, m, s, ms);// getline(cin, st);getchar();while (getline(cin, st)) {if (st.size() == 0) {cout << "\n";break;}cout << st << "\n";}}return 0;
}

J.Just Send the Email

题意

有一棵树(?),找出每个结点到叶子结点的最小距离(叶子结点本身的距离为1),求和,与总结点数相比

思路

用逆向思维,从叶子结点进行BFS即可

代码

/** @Author: Icey_dying* @Date: 2021-10-04 13:10:13* @LastEditors: Icey_dying* @LastEditTime: 2021-10-04 13:28:44* @FilePath: \Icey_dying\competition\2021\2021.10\2021.10.2\J.cpp*/
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 5;
long long quickmod(long long a, long long b)
{long long ret = 1;while (b) {if (b & 1)ret = ret * a % mod;a = a * a % mod;b /= 2;}return ret;
}
vector<int> v[N];
queue<int> q;
int n;
bool vis[N];
int depth[N];
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);memset(vis, false, sizeof(vis));cin >> n;for (int i = 2, x; i <= n; i++) {cin >> x;vis[x] = true;v[x].push_back(i);v[i].push_back(x);}memset(depth, 0, sizeof(depth));int cnt = n;for (int i = 1; i <= n; i++)if (!vis[i]) {cnt--;q.push(i);depth[i] = 1;}for (int i = 1; i <= n; i++)vis[i] = !vis[i];while (!q.empty()) {int ans = q.front();// cout << ans << endl;q.pop();for (auto i : v[ans]) {if (!vis[i]) {cnt--;q.push(i);vis[i] = true;depth[i] = depth[ans] + 1;}}if (!cnt)break;}// for (int i = 1; i <= n; i++)//     cout << depth[i] << " \n"[i == n];long long wow = 0;for (int i = 1; i <= n; i++)wow += depth[i];// cout << wow << endl;long long hh = n;int ggcd = __gcd(wow, hh);wow /= ggcd;hh /= ggcd;cout << wow % mod * quickmod(hh, mod - 2) % mod << endl;return 0;
}

K.Kids at the Party

题意

Jaime有5个朋友,现有一些糖果,Jaime想要和朋友一起聚会的前提是他和朋友拥有相同的糖果,且聚会至少有2人,问聚会上可以有几个小朋友(包括Jaime)

思路

直接求糖果可以被几整除即可(e.g. 2,3,4,5,6)

代码

/** @Author: Icey_dying* @Date: 2021-10-02 15:15:01* @LastEditors: Icey_dying* @LastEditTime: 2021-10-02 15:24:37* @FilePath: \Icey_dying\competition\2021\2021.10\2021.10.2\K.cpp*/
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
char a[N];
int t;
int b[10];
int main()
{cin >> t;while (t--) {cin >> a;int ans = 0;memset(b, 0, sizeof(b));if ((a[strlen(a) - 1] - '0') % 2 == 0) {b[2] = 1;ans = 0;if (strlen(a) > 1)ans = (a[strlen(a) - 2] - '0') * 10 + a[strlen(a) - 1] - '0';if (strlen(a) == 1 && (a[strlen(a) - 1] - '0') % 4 == 0)b[4] = 1;if (strlen(a) > 1 && ans % 4 == 0)b[4] = 1;}if ((a[strlen(a) - 1] - '0') % 5 == 0)b[5] = 1;ans = 0;for (int i = 0; i < strlen(a); i++) {ans += a[i] - '0';}if (ans % 3 == 0) {b[3] = 1;if (b[2])b[6] = 1;}ans = 0;for (int i = 2; i <= 6; i++)ans += b[i];if (ans) {int cnt = 0;for (int i = 2; i <= 6; i++) {if (b[i]) {cnt++;cout << i << " \n"[cnt == ans];}}} elsecout << "-1\n";}return 0;
}

L.Leonel and the powers of two

题意

问 2 k 2^k 2k的表达式
规则如下:
2 ( k = 1 ) 2(k=1) 2(k=1)
2 ∗ 2 k − 1 2*2^{k-1} 2∗2k−1(k为奇数)
( 2 k 2 ) 2 (2^{\frac{k}{2}})^2 (22k​)2(k为偶数)

思路

直接写一个函数,递归调用即可

代码

/** @Author: Icey_dying* @Date: 2021-10-02 14:56:53* @LastEditors: Icey_dying* @LastEditTime: 2021-10-02 15:00:09* @FilePath: \Icey_dying\competition\2021\2021.10\2021.10.2\L.cpp*/
#include <bits/stdc++.h>
using namespace std;
string f(long long n)
{if (n == 1)return "2";string s;if (n % 2)return "(2*" + f(n - 1) + ")";elsereturn "(" + f(n / 2) + ")^2";
}
int t;
long long n;
int main()
{cin >> t;while (t--) {cin >> n;cout << f(n) << endl;}return 0;
}

2021 ICPC Gran Premio de Mexico 1ra Fecha相关推荐

  1. 2022 ICPC Gran Premio de Mexico 1ra Fecha(一)

    今天大部分时间都花在了上一场沈阳站的L题上了,一个树上背包+容斥原理,看了好久才理解,就不硬敲上了,再想几天在写题解.然后今天自己写了场ICPC墨西哥站的 ICPC Gran Premio de Me ...

  2. 2022 ICPC Gran Premio de Mexico 1ra Fecha 题解

    A 线性基 由于数组异或和固定,因此异或和为奇数的位置可以不用考虑,无论如何分,总是只能有1个为奇数,总贡献不变. 考虑异或和为偶数的位置,利用线性基求其中一部分尽可能大的结果,另一部分结果相同. # ...

  3. 2022 ICPC Gran Premio de Mexico 1ra Fecha (B、D、E、F)

    小技巧: stoi(str,0,2) 将从0开始的二进制串转化为十进制串 不是标准函数,慎用(一般应该没问题吧--) 本次补的题应该都是铜.银牌题,可能欧洲场简单很多 D. Different Pas ...

  4. 【2021 ICPC Gran Premio de Mexico 2da Fecha F】Flipped Factorization 题解

    题目大意   设 x x x 的质因数分解为 p 1 c 1 p 2 c 2 ⋯ p m c m p_1^{c_1}p_2^{c_2}\cdots p_m^{c_m} p1c1​​p2c2​​⋯pmc ...

  5. 2021 ICPC Gran Premio de Mexico 2da Fecha(C,D,G,I)

    题目 C. Cut the Deck D. Dislike the Raisins G. Grid of Letters I. Integer Multiplicative Persistence C ...

  6. 2023 ICPC Gran Premio de Mexico 1ra Fecha

    待更新 目录 1 A Aliases B Bucket storing D Dynamic Collection E Employees Bonus G Growing game J Jumping ...

  7. 训练记录番外篇(2):2022 ICPC Gran Premio de Mexico 2da Fecha

    2022 ICPC Gran Premio de Mexico 2da Fecha 2022.10.3 之前训得ak场,个人认为很edu. (顺便一提,可能这个训练记录番外系列的比赛都非常edu,十分 ...

  8. 2022 ICPC Gran Premio de Mexico 2da Fecha Final standings - K. Krystalova‘s Trivial Problem

    K. Krystalova's Trivial Problem time limit per test1 second memory limit per test256 megabytes input ...

  9. 2022 ICPC Gran Premio de Mexico Repechaje 题解

    目录 A. Average Walk(签到) 题意: 思路: 代码: C. Company Layoffs(签到) 题意: 思路: 代码: D. Denji1(模拟/二分) 思路: 代码: K. Ke ...

最新文章

  1. [转]查询oracle数据库的数据库名、实例名、ORACLE_SID
  2. 为什么375×667是移动端原型设计的最佳分辨率:flutter 设计稿尺寸最好也是375×667...
  3. 从centos7默认安装的/home中转移至根目录/ (LVM操作简明教程)
  4. Form.php 日期表单,Bootstrap日期和时间表单组件使用方法
  5. Milking Time(POJ-3616)
  6. 用 git 维护 vim 代码
  7. java怎样将日期本土化_Java中的日期操作
  8. lisp取消选集选中状态_为什么对话框创建后是隐藏状态的
  9. 台式计算机怎么设置自动锁屏,台式机win7怎么设置自动锁屏
  10. Vue表单设计器的终极解决方案
  11. Kettle5.2 Carte.bat 页面中文乱码
  12. 如何在Ubuntu 14.04中读取MOBI文件
  13. uniapp自定义导航栏,手机顶部通知栏字体颜色修改
  14. 基于python3.7的4环电阻读数工具
  15. 收藏!数学节为你推荐10本数学好书!
  16. 路由器基本配置、静态路由
  17. vue 独享路由守卫
  18. Etyma01 ced ceed cess
  19. 鱼眼相机图像畸变校正
  20. android mm是什么版本,Android中m、mm、mmm、mma、mmma的区别

热门文章

  1. oracle替换手机号中间的4位为*号(姓名,手机号,邮箱脱敏)
  2. 微信公众号01: ase实现access_token的存储和被动刷新
  3. 2006-10-30 18:37:00 著名Linux内核程序员大鹰 ox啊
  4. 七(10)springtask-RabbitMq-内容审核
  5. 基因编辑c语言,基因编辑为何失败?那是因为Cas9霸着C位
  6. 如何消除文法的二义性
  7. 智能网联建设核心评价指标探讨
  8. 苹果系统安装Java开发环境JDK
  9. 微信这几个好用的功能,你该知道
  10. 微信小程序-医护人员排班系统