当前位置: 首页 > news >正文

2025-10-25 MXOJ 【CSP-S】-- 模拟四 【郑州一中】record

比赛链接:Contests

A.put

原题链接:Problems

简单的贪心,直接切了。10点58分榜上的rank1大佬写了个dp,但我研究了一下,那个dp也只是把贪心的过程记录在了dp数组中。

那么直接上代码吧!

正解:

#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
long long n;
struct node{long long p, h;
}a[N];
bool cmp(node x, node y){return x.p < y.p;
}
int read(){char c = getchar();long long x = 0, f = 1;while (c < '0' || c > '9'){if (c == '-')f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = x * 10 + (c - '0');c = getchar();}return x * f;
}
int main(){n = read();for (int i = 1; i <= n; i++){a[i].p = read();a[i].h = read();}sort(a + 1, a + n + 1, cmp);long long ans = 2;for (int i = 2; i < n; i++){int lst = a[i - 1].p;int nxt = a[i + 1].p;if (a[i].p - a[i].h > lst){ans++;continue;}if (a[i].p + a[i].h < nxt){ans++;a[i].p += a[i].h;}}printf("%d", ans);
}

常数很大吗?机房普遍都在100ms以内,我跑了131ms/(ㄒoㄒ)/~~

B.match

原题链接:Problems

错误分析:乱打暴力,写了O(n^{2}log^{2}n),其实思考一下就可以优化到O\left ( nlogn \right )

思路分析:相当于把A数组进行滑动,而前面的是已经存在的,只改变一个位置就可以了。

正解:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e5 + 10;
ll n, m, q, p;
ll a[N], o[N], mx[N], ans[N];
struct node{ll num, w;
}b[N];
bool cmp(node q, node p){return q.num < p.num;
}
long long read(){char c = getchar();long long x = 0, f = 1;while (c < '0' || c > '9'){if (c == '-')f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = x * 10 + (c - '0');c = getchar();}return x * f;
}
int main(){    n = read();n++;for (ll i = 1; i <= n; i++){b[i].num = read();b[i].w = i;}for (ll i = 1; i < n; i++){a[i] = read();}sort(a + 1, a + n);sort(b + 1, b + 1 + n, cmp);for (ll i = n; i >= 2; i--){o[i] = max(o[i + 1], b[i].num - a[i - 1]);}ans[b[1].w] = o[2];for (ll i = 2; i <= n; i++){mx[i] = max(b[i - 1].num - a[i - 1], mx[i - 1]);ans[b[i].w] = max(mx[i], o[i + 1]);}for (ll i = 1; i <= n; i++){printf("%lld ", ans[i]);}return 0;
}

膜拜呱呱!

C.div

显然我只会O(n),但要求O(\sqrt{n}).

传言是根号分治的板子,机房AeeE5x这么强吗?

那么,直接上正解吧!!!

#include<bits/stdc++.h>
#define int long long
using namespace std;
int prexor(int n){if(n == 2) return 3;if(n % 2 == 1) return ((n + 1) >> 1) % 2;else return n + ((n >> 1) % 2);
}
void solve(int n){int ans = 0;int nowfactor = 1;for ( ; nowfactor <= n; nowfactor++){if ((n / nowfactor) % 2 == 1) ans ^= nowfactor;elseans ^= 0;if (nowfactor > sqrt(n) && (n / nowfactor != n / (nowfactor + 1))) break; }nowfactor++;int maxdiv = n / nowfactor;for (int nowdiv = 1; nowdiv <= maxdiv; nowdiv += 2){int minfac = (n / (nowdiv + 1)) + 1;int maxfac = (n / nowdiv);ans ^= prexor(maxfac) ^ prexor(minfac - 1);}cout << ans << "\n";
}
int n;
signed main(){ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);freopen("div.in", "r", stdin);freopen("div.out", "w", stdout);cin >> n;solve(n);return 0;
}

严肃学习根号分治……

http://www.dtcms.com/a/537763.html

相关文章:

  • 网络公司发生网站建设费分录响应式自适应织梦网站模板
  • 2025年内蒙古自治区职业院校技能大赛高职组“软件测试”赛项技能操作样题
  • 无锡建设银行网站网战
  • Java(IO流)
  • 管家婆财贸ERP BB118.付款单单据控制
  • 做男性服装的网站网站首页的快照更新慢
  • 使用Docker安装PandaWiki(AI知识库)
  • JT808,JT1078协议,Java获取音频数据播放时长
  • 国外网站设计风格微信网站页面
  • 免费观看行情软件网站进入专业企业展厅设计公司
  • Hive简介
  • 建网站要自己买服务器吗苏州专业高端网站建设公司哪家好
  • 网站首页布局设计用什么宝塔负载100wordpress
  • Future和CompletableFuture详解
  • 公司网站出现空白页网站建设义乌
  • 高并发视频直播系统源码:从直播架构设计开发到搭建部署上线
  • 做一个跨境电商网站西地那非使用三大忌
  • 网络营销的营销方式是什么广州市网络seo外包
  • 迈诺网站建设专业app制作开发公司
  • 解决报错No module named ‘numpy.exceptions‘
  • Git学习-5
  • 关于Mysql的学习三(事务)
  • hot100面试150——十二周
  • 免费网站模板psd崇明装修公司哪家好
  • 公司做网站的申请上海热点新闻
  • 《Redis 开发与运维》学习笔记[特殊字符]
  • 上海网站建设公司电网页拖拽设计工具
  • cdn网站加速有用吗网页游戏传奇霸主攻略
  • 保护你的创意!让图片拥有盲水印[特殊字符][特殊字符]
  • NEFTUNE