【NOIP2018pj】题解
【NOIP2018pj】题解
\(T1\)
题面
题解
好像并没有什么好说的。。。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
string s;
int main () {
getline(cin, s);
int ans = 0;
for (int i = 0, l = s.size(); i < l; i++) {
if (isdigit(s[i]) || ('a' <= s[i] && s[i] <= 'z') || ('A' <= s[i] && s[i] <= 'Z')) ans++;
}
printf("%d\n", ans);
return 0;
}
\(T2\)
题面
题解
先把每一边贡献算出来再扫一遍即可
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (ch != '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return data * w;
}
#define MAX_N 100005
int N, a[MAX_N];
int m, p1, s1, s2;
typedef long long ll;
ll Left = 0, Right = 0, dlt = 0;
int ans = 0;
int main () {
N = gi();
for (int i = 1; i <= N; i++) a[i] = gi();
m = gi(), p1 = gi(), s1 = gi(), s2 = gi();
a[p1] += s1;
for (int i = 1; i < m; i++) Left += 1ll * a[i] * (m - i);
for (int i= m + 1; i <= N; i++) Right += 1ll * a[i] * (i - m);
ans = m; dlt = abs(Left - Right);
for (int i = 1; i < m; i++) {
ll res = abs(Left + 1ll * s2 * (m - i) - Right);
if (res < dlt) ans = i, dlt = res;
else if (res == dlt) ans = min(i, ans);
}
for (int i = m + 1; i <= N; i++) {
ll res = abs(Right + 1ll * s2 * (i - m) - Left);
if (res < dlt) ans = i, dlt = res;
else if (res == dlt) ans = min(i, ans);
}
printf("%d\n", ans);
return 0;
}
\(T3\)
\(T4\)
【NOIP2018pj】题解的更多相关文章
- 【LG5017】[NOIP2018pj]摆渡车
[LG5017][NOIP2018pj]摆渡车 题面 洛谷 题解 震惊!普及组竟然考斜率优化??? 当然有其他的方法 首先我们转化一下模型 此题可以变为: 在一根时间轴上有一些点,每个时间点\(i\) ...
- 【LG5018】[NOIP2018pj]对称的二叉树
[LG5018][NOIP2018pj]对称的二叉树 题面 洛谷 题解 看到这一题全都是用\(O(nlogn)\)的算法过的 考场上写\(O(n)\)算法的我很不开心 然后就发了此篇题解... 首先我 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
随机推荐
- JavaScript正则表达式_常用的正则
一.检查邮政编码 var pattern = /[1-9][0-9]{5}/; //共 6 位数字,第一位不能为0 {5}表示后面5位0到9 var str = '224000'; alert(pa ...
- pythone 请求响应字典
_RESPONSE_STATUSES = { # Informational 100: 'Continue', 101: 'Switching Protocols', 102: 'Processing ...
- selenium + python自动化测试unittest框架学习(五)webdriver的二次封装
因为webdriver的api方法很长,再加上大多数的定位方式是以xpath方式定位,更加让代码看起来超级长,为了使整体的代码看起来整洁,对webdriver进行封装,学习资料来源于虫师的<se ...
- Win32多线程之核心对象
CreateThread()传回两个值,用以识别一个新的线程.第一个值是个Handle, 这也是CreateThread()的返回值,大部分与线程有关的API函数都需要它.第二个值是由lpThrea ...
- java学习笔记 --- 多线程(多线程的控制)
1.线程休眠 public static void sleep(long millis) public class ThreadSleep extends Thread { @Override ...
- Eclipse常用快捷键(持续更新)
编辑相关快捷键 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1.[Ctrl+O] 显示类中方法和属性的大纲, ...
- 错误:maximum number of expressions in a list is 1000
某一日发现这么如下这么一个错误 --> maximum number of expressions in a list is 1000 原因:因为SQL语句中用到了IN字句,而IN中的元素个数 ...
- CentOS7 安装 Docker 以及 Shipyard管理端
简介: Docker 是一个开源工具,它可以让创建和管理 Linux 容器变得简单.容器就像是轻量级的虚拟机,并且可以以毫秒级的速度来启动或停止. Docker 帮助系统管理员和程序员在容器中开发应用 ...
- oracle数据库每天自动备份
现在介绍一下我们项目中使用exp工具每天自动对oracle进行备份. 用这个工具我们可以使用命令行的方式也可以使用pl/sql developer来进行导出. 我们要使用exp命令来导出oracle的 ...
- ionic3 监听软键盘的高度
ionic1 和普通cordova的大家都知道 就是看ionic3 和4 https://blog.csdn.net/sean_css/article/details/70243893 ionic c ...