题解 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 ...
随机推荐
- PHP函数(二)-不定参数的传递
如果要传递不定数量的参数,需要使用func_get_args()函数来传递 func_num_args()函数用来返回参数的总数 <?php function more_args(){ $arg ...
- 【树莓派】RASPBIAN镜像初始化配置
[树莓派]如何烧录镜像详细版 接上一节,系统已经烧录完毕了,将其放置于树莓派然后运行起来 我是直接接显示器了,若有需要转接头的自行淘宝搜索购买~~电源使用的是5V 2.5A的 首次开机会时间较长 且有 ...
- Linux批量“解压”JAR文件
当你需要”解压“很多jar文件时,可以通过很多方式进行,比如下面这种 1,列出每一个jar文件名,逐个展开 for i in $(ls *sour*.jar);do jar xvf $i;done
- Spring AOP基于注解的“零配置”方式实现
为了在Spring中启动@AspectJ支持,需要在类加载路径下新增两个AspectJ库:aspectjweaver.jar和aspectjrt.jar.除此之外,Spring AOP还需要依赖一个a ...
- Stars(树状数组单点更新)
Astronomers often examine star maps where stars are represented by points on a plane and each star h ...
- FatMouse' Trade(Hdu 1009)
Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wareho ...
- 【原】Coursera—Andrew Ng机器学习—Week 1 习题—Linear Regression with One Variable 单变量线性回归
Question 1 Consider the problem of predicting how well a student does in her second year of college/ ...
- Linux的基本指令--目录和文件和文件属性和文件用户组
目录和文件 一 . ls:列出目录的内容,未给出目录名或是文件名时,就显示当前目录的信息. -a 列出隐藏文件,文件中以”.”开头的均为隐藏文件,如:~/.bashrc -l 列出文件的详细信息 ...
- 在VMware中为Red Hat配置静态ip并可访问网络-Windows下的VMware
首先确保虚拟网卡(VMware Network Adapter VMnet8)是开启的,然后在windows的命令行里输入“ipconfig /all”,找到VMware Network Adapte ...
- SaeStorage使用示例
新浪SAE官方地址:http://apidoc.sinaapp.com/sae/SaeStorage.html SaeStorage的代码详细:http://apidoc.sinaapp.com/__ ...