【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 ...
随机推荐
- BZOJ 1192 鬼谷子的钱袋 找规律
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1192 题目大意: 鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向 ...
- 2241. [SDOI2011]打地鼠【暴力+剪枝】
Description 打地鼠是这样的一个游戏:地面上有一些地鼠洞,地鼠们会不时从洞里探出头来很短时间后又缩回洞中.玩家的目标是在地鼠伸出头时,用锤子砸其头部,砸到的地鼠越多分数也就越高. 游戏中的锤 ...
- 解决MySQL新建用户后无法登录问题
在PHPMyAdmin里创建了一个新的用户,并且创建了密码,但是却一直无法使用这个账户登录到MySQL里. 解决过程分享给大家~ 1.以root身份登录mysql 2.删除MySQL中默认存在一个用户 ...
- valgrind massif内存分析[转]
valgrind检查内存泄露 #valgrind ./程序 内存泄漏问题,我们有memcheck工具来检查.很爽.但是有时候memcheck工具查了没泄漏,程序一跑,内存还是狂飙.这又是什么问题. ...
- Maven Jetty插件使用
本机环境 JDK8 Maven 3.5 Jetty 9.3 Eclipse Mars pom.xml配置 在你的 pom.xml 文件中添加 jetty 插件的描述信息 <build> & ...
- Facade(外观)模式
1. 概述 外观模式,我们通过外观的包装,使应用程序只能看到外观对象,而不会看到具体的细节对象,这样无疑会降低应用程序的复杂度,并且提高了程序的可维护性.例子1:一个电源总开关可以控制四盏灯.一个风扇 ...
- a、button、input点击获取焦点时出现蓝色边框,如何去掉
a,button,input{ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-user-modify: read-write-plain ...
- 生成Html 测试报告
1.引入HTMLTestRunner 下载HTMLTestRunner.py 从http://tungwaiyip.info/software/HTMLTestRunner.html 将下载的HTML ...
- Source folder is not on the Java build class path
源文件夹不在Java构建类路径上 只需右键单击文件夹src - > build path - >Using source folders就是这样
- 你不知道的css之 width “继承”篇。
众所周知,css的三大特性分别是 继承性,层叠性,和优先级. 那么这里就详细说一下css中width的继承性及其特殊情况. 继承性概念详解:css的继承性指的被包在内部的标签拥有外部标签的样式性,子元 ...