【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】题解的更多相关文章

  1. 【LG5017】[NOIP2018pj]摆渡车

    [LG5017][NOIP2018pj]摆渡车 题面 洛谷 题解 震惊!普及组竟然考斜率优化??? 当然有其他的方法 首先我们转化一下模型 此题可以变为: 在一根时间轴上有一些点,每个时间点\(i\) ...

  2. 【LG5018】[NOIP2018pj]对称的二叉树

    [LG5018][NOIP2018pj]对称的二叉树 题面 洛谷 题解 看到这一题全都是用\(O(nlogn)\)的算法过的 考场上写\(O(n)\)算法的我很不开心 然后就发了此篇题解... 首先我 ...

  3. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  4. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  5. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  6. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  7. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  8. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  9. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

随机推荐

  1. CATransition:视图替换动画:子视图的增删查改

    CATransition通常用于通过CALayer控制UIView内子控件的过渡动画,比如删除子控件,添加子控件,切换两个子控件等. 用于子视图的增删查改:

  2. fill & stroke

    - (void)stroke Draws a line along the receiver’s path using the current drawing properties. - (void) ...

  3. Why Reactive(Cocoa)?-时间线、输入、输出、复杂性、异步、状态、聚合

    To put it another way, the output at any one time is the result of combining all inputs. The output ...

  4. 11GR2 中的常见 RMAN 问题

    版权声明:本文为博主原创文章,欢迎转载验证并评论,谢谢! https://blog.csdn.net/li70803/article/details/34104511 本文是Oracle suppor ...

  5. 【[HEOI2016/TJOI2016]字符串】

    码农题啊 上来先无脑一个\(SA\)的板子,求出\(SA\)和\(het\)数组 我们只需要从\(sa[i]\in[a,b]\)的所有\(i\)中找到一个\(i\)使得\(sa[i]\)和\(rk[c ...

  6. 【[ZJOI2008]泡泡堂】

    想贪心就是反复\(hack\)自己的过程 首先这很田忌赛马,但是又不完全一样 田忌赛马保证了所有马的实力不同,因此没有平局 田忌赛马的策略是当自己最强的马比不过对方最强的马的时候,就用自己最弱的马来自 ...

  7. 如何使用Loadrunner12录制WebSocket脚本

    简单说一下,关于Loadrunner12对WebSocket的支持可以参照以下文档: http://community.hpe.com/t5/LoadRunner-and-Performance/As ...

  8. win10里如何在中文输入法里添加美式键盘

    在控制面板打开“时钟.语言和区域”设置界面,选中“语言”设置  “语言”设置里点击“添加语言” 在添加语言设置里选择“英语”,并点击“打开”按钮,在“区域变量”设置页面里选择“英语(美国)” ,并点击 ...

  9. 7、Web Service-IDEA-jaxws规范下的 服务端/客户端 开发

    前提简介:这里之后即使基于IDEA进行开发的,风格与之前有些不同之处! 1.服务端的开发 1.创建新的项目 2.pom.xml 添加开发时所需要的依赖 <?xml version="1 ...

  10. linux文件系统写过程简析

    linux写入磁盘过程经历VFS ->  页缓存(page cache) -> 具体的文件系统(ext2/3/4.XFS.ReiserFS等) -> Block IO ->设备 ...