题目链接

先吐槽一番:本宝宝好久没写过题解了。。。
首先我们想一个贪心策咯。
就是我们预处理出前缀和,然后一边扫过去,记录一个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】的更多相关文章

  1. [CF] 950B Intercepted Message

    B. Intercepted Message time limit per test1 second memory limit per test512 megabytes inputstandard ...

  2. 469 B. Intercepted Message

    http://codeforces.com/problemset/problem/950/B Hacker Zhorik wants to decipher two secret messages h ...

  3. CF950B Intercepted Message_双指针法

    本来想直接上权值线段树维护区间最值,不过可以用双指针法,就使问题变得简洁. Code: #include<iostream> using namespace std; const int ...

  4. 【codeforces】【比赛题解】#950 CF Round #469 (Div. 2)

    剧毒比赛,至少涨了分对吧.: ( [A]Left-handers, Right-handers and Ambidexters 题意: 有\(l\)个右撇子,\(r\)个左撇子,\(a\)个双手都惯用 ...

  5. Codeforces Round #469 Div. 2题解

    A. Left-handers, Right-handers and Ambidexters time limit per test 1 second memory limit per test 25 ...

  6. ACM 第七天

    水题 B - Minimum’s Revenge There is a graph of n vertices which are indexed from 1 to n. For any pair ...

  7. Codeforces Round #469 Div. 2 A B C D E

    A. Left-handers, Right-handers and Ambidexters 题意 \(l\)个左撇子,\(r\)个右撇子,\(a\)个两手均可.要组成一支队伍,里面用左手的人数与用右 ...

  8. Eclipse 4.2 failed to start after TEE is installed

    ---------------  VM Arguments---------------  jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...

  9. 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 ...

随机推荐

  1. 第八章 数据库连接JDBC(待续)

    ············

  2. Windows 环境下Java调用CRF++详解

    1.步骤一览 2.步骤详情 2.1.环境准备 Swig(Simplified Wrapper and Interface Generator)下载,Windows操作系统直接解压即可使用 CRF++( ...

  3. javascript原型继承中的两种方法对比

    在实际的项目中,我们通常都是用构造函数来创建一个对象,再将一些常用的方法添加到其原型对象上.最后要么直接实例化该对象,要么将它作为父类,再申明一个对象,继承该父类. 而在继承的时候有两种常用方式,今天 ...

  4. SqlServer——常见问题汇总

    1.存储过程手动执行正常,应用程序高并发允许时,数据成倍数增加 通常此类问题是由于存储过程中使用了永久表作为中间表,用以存储临时数据.当高并发时,比如同时执行3次,则同时往中间表中插入3倍的数据,得到 ...

  5. leetcode598

    public class Solution { public int MaxCount(int m, int n, int[,] ops) { ); ); || col == ) { return m ...

  6. Asp.Net framework 类库 自带的缓存 HttpRuntime.Cache HttpContext.Cache

    两个Cache 在.NET运用中经常用到缓存(Cache)对象.有HttpContext.Current.Cache以及HttpRuntime.Cache,HttpRuntime.Cache是应用程序 ...

  7. jquery-attr与prop

    问题:经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法获取其真实值,下面介绍这两种方法的区别: 1.通过prop方法获取checked属性 ...

  8. java中的报错机制

    异常:Exception,程序运行过程中因为一些原因,使得程序无法运行下去 注意:在程序能够运行起来的情况,不是程序编译通不过 举例:读文件,点击一个按钮,文件不存在:访问数据库服务器,数据库服务器停 ...

  9. scala中存在的问题

    2017-12-27 scala学习中存在的问题: 1.表达式的概念要搞清楚 2.八种基本数据类型要搞清楚 Byte\Short\Int\Long\Char\Boolean\Double\Float都 ...

  10. 06-Location详解之精准匹配

    之前nginx不是编译过吗?现在重新make install一下. 刚刚这个是我们新安装的.原始版的nginx,配置文件比较少,便于我们做调试. 试试精准匹配的概念. 匹配的是/.优先匹配这个最精准的 ...