题解 CF950B 【Intercepted Message】
先吐槽一番:本宝宝好久没写过题解了。。。
首先我们想一个贪心策咯。
就是我们预处理出前缀和,然后一边扫过去,记录一个l1,l2和一个n1,n2。
分别表示我们现在第一个数组切到l1,上一次切是在n1处。l2,n2是表示第二个数组。
如果$ans1[l1]-ans1[n1]$ $=$ $ans2[l2]-ans2[n2]$ 就切一刀。(具体见代码)。
否则,如果$ans1[l1]-ans1[n1]$ $>$ $ans2[l2]-ans2[n2]$ 就把l2++。反之,l1++
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int m,n;//长度
int x[];
int y[];//储存序列
int anx[];//前缀和
int any[];
int l1=,n1;//如上所说,
int l2=,n2;//初始化,l1,l2均为一。n1,n2因为没切过,所以均为0;
int ans;//记录答案
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d",&x[i]);
anx[i]=anx[i-]+x[i];
}
for(int i=;i<=m;i++)
{
scanf("%d",&y[i]);
any[i]=any[i-]+y[i];
}//输入并处理前缀和。
while(l1<=n&&l2<=m)//判断有没有切完整个序列。
{
// printf("%d %d %d %d %d %d\n",l1,n1,l2,n2,(anx[l1]-anx[n1]),(any[l2]-any[n2]));
if((anx[l1]-anx[n1])>(any[l2]-any[n2])) l2++;
else if((anx[l1]-anx[n1])<(any[l2]-any[n2])) l1++;//如上所说。
else if((anx[l1]-anx[n1])==(any[l2]-any[n2]))
{
n1=l1;n2=l2;//第一个序列从l1切,第二个从l2切,更新n1,n2;
ans++;//答案+1;
l1++;//然后继续向后扫。
l2++;
}
}
printf("%d",ans);//输出答案
return ;//程序拜拜~
}
//样例在此
/*
7 6
2 5 3 1 11 4 4
7 8 2 4 1 8 3 3 3
1 10 100
1 100 10 2 1 4
4
1 1 1 1 1
*/
如果对大家有帮助的话,希望大家留言支持呦~
题解 CF950B 【Intercepted Message】的更多相关文章
- [CF] 950B Intercepted Message
B. Intercepted Message time limit per test1 second memory limit per test512 megabytes inputstandard ...
- 469 B. Intercepted Message
http://codeforces.com/problemset/problem/950/B Hacker Zhorik wants to decipher two secret messages h ...
- CF950B Intercepted Message_双指针法
本来想直接上权值线段树维护区间最值,不过可以用双指针法,就使问题变得简洁. Code: #include<iostream> using namespace std; const int ...
- 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)
剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用 ...
- Codeforces Round #469 Div. 2题解
A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...
- ACM 第七天
水题 B - Minimum’s Revenge There is a graph of n vertices which are indexed from 1 to n. For any pair ...
- Codeforces Round #469 Div. 2 A B C D E
A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...
- Eclipse 4.2 failed to start after TEE is installed
--------------- VM Arguments--------------- jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...
- python + web自动化,点击不生效,提示“selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (117, 674)”
前言: 在做web自动化时,遇到一个缩放了浏览器比例的操作,从100%缩小到80%,再进行点击的时候,弹出报错信息,无法点击 selenium.common.exceptions.ElementCli ...
随机推荐
- leetcode452
public class Solution { public int FindMinArrowShots(int[,] points) { // multidimensional array cann ...
- nat123安装启动教程帮助
转自:http://www.nat123.com/Pages_17_291.jsp 本文就nat123安装启动可能遇到的问题及与安全狗影响处理. 下载安装nat123客户端安装包.第一次安装使用,可选 ...
- Oracle DATABASE LINK(DBLINK)创建
数据库全局名称可以用以下命令查出: SELECT * FROM GLOBAL_NAME; 修改可以用以下语句来修改参数值: ALTER SYSTEM SET GLOBAL_NAME=TRUE/FALS ...
- UDP数据报
服务器端:Server 函数: 1.inet_addr()://把IP地址转换为长整型2.inet_ntoa();//将长整型转换为IP地址3.socket的阻塞和非阻塞: 阻塞模式下: 在程序中,“ ...
- GIT常用命令以及作用【备忘】
git commit 提交一个修改 git branch branchName 新建一个branchName的分支 git merge branchName 将当前分支与branchName分支合 ...
- 深入剖析SolrCloud(一)
作者:洞庭散人 出处:http://phinecos.cnblogs.com/ 本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由 ...
- 值得一做》关于一道DP+SPFA的题 BZOJ1003 (BZOJ第一页计划) (normal-)
这是一道数据范围和评测时间水的可怕的题,只是思路有点难想,BUT假如你的思路清晰,完全了解怎么该做,那就算你写一个反LLL和反SLE都能A,如此水的一道题,你不心动吗? 下面贴出题目 Descript ...
- PHP程序员求职经验总结
这次来深圳找工作,是我人生中第一次正式的求职,也是第一份正式的工作.这几天收获不少,总结一下,"供后人参考"; 从7月23来深圳到今天刚好一个星期,这7天内我发了18封求职邮件,在 ...
- 通过event事件来控制红绿灯通行车辆
事件的初始值为False,所以最开始就是红灯,先模拟红绿灯的规律,设定为每两秒变换一次灯,然后再模拟车辆通行,通过事件来将两者的事件结合起来, 当事件为False时,为红灯,车辆处于等待状态,一直wa ...
- Socket接口原理及用C#语言实现
首先从原理上解释一下采用Socket接口的网络通讯,这里以最常用的C/S模式作为范例,首先,服务端有一个进程(或多个进程)在指定的端口等待客户来连接,服务程序等待客户的连接信息,一旦连接上之后,就可以 ...