题解 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 ...
随机推荐
- 2014.8.25 VS新建项目模板消失解决方法
Vs2005 新建项目时windows应用程序模板消失问题解决方法: 1:进入C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\ ...
- sql 2012先分离迁移mdf mlf 文件到别的机器后附加 数据库成只读的修复方法
SQL Server2008附加数据库之后显示为只读时解决方法 从本地分离的数据库文件放到远程服务器上,附加数据库出现数据库为(只读情况) 阅读了以下两篇文章: 第一篇:http://blog.c ...
- sql server生成递归日期、连续数据
WITH Date AS ( SELECT CAST('2008-08-01' AS DATETIME) da UNION ALL FROM Date WHERE da < '2008-08-2 ...
- java定时任务调度工具Timer与Quartz的区别
Timer与Quartz的区别有三点: 1.出身不同:Timer由jdk直接提供,调用方式简单粗暴,不需要其它jar包支持.Quartz并非jdk自带,需要引入相应的jar包 2.能力区别:主要体现在 ...
- Redis搭建(二):主从复制
一.引言 Redis有三种集群模式: 第一个就是主从模式 第二种“哨兵”模式,在Redis 2.6版本开始提供,2.8版本稳定 第三种是Cluster集群模式,在Redis 3.x以后的版本才增加进来 ...
- consul watch
consul watch -type key -key mhc ./key_handler.py [root@mhc consul]# cat key_handler.py #!/usr/bin/py ...
- UIRect中的Anchor组件
[UIRect中的Anchor组件] Anchor用于实现粘着功能,寄存于UIRect类中.Anchor的类型有三种: 1.None:不使用跟随功能. 2.Unified:四条边使用相同的Target ...
- SpringMVC总结三:请求Controller返回视图类型以及请求方式、参数介绍
视图解析,请求Controller返回的视图类型: @Controller @RequestMapping("/test") public class TestController ...
- 并发之AtomicIntegerArray
5 并发之AtomicIntegerArray 该类是Java对Integer数组支持的原子性操作:在认识这个类之前我们先来看一个方法,这个方法是Integer类中的: public sta ...
- 8-python模拟登入(无验证码)
方式: 1.手动登入,获取cookie 2.使用cookielib库 和 HTTPCookieProcessor处理器 #_*_ coding: utf-8 _*_ ''' Created on 20 ...