B. Spotlights

题意

  有n×m个格子的矩形舞台,每个格子里面可以安排一个演员或聚光灯,聚光灯仅可照射一个方向(俯视,上下左右)。若聚光灯能照到演员,则称为“good position”,求:共有多少“good position”(同一格子的不同照射方向算作不同的position)。

分析

  对于一行而言,只要分别找到两侧第一个演员的位置(命名“标志位”),就能确定这一行的“good position”。两标志位以外的聚光灯只能投向一个方向(∵两标志位在同一侧),标志位之间的聚光灯能投向两个方向(即左右两侧的标志位)。因此,只要计算出两标志位以外的0元个数加上标志位之间0元个数×2就是这一行的“good position”的个数。列同理,然后全部相加即可。

代码

 #include <bits/stdc++.h>
#define max_n 1001 using namespace std; int n, m, r1[max_n], r2[max_n], c1[max_n], c2[max_n], r0[max_n], c0[max_n], ans;
int main()
{
std::ios::sync_with_stdio();
cin >> n >> m;
int temp;
for(int i=; i<=n; i++) { // 1e6
for(int j=; j<=m; j++) {
cin >> temp;
if(temp) {
if(!r1[i]) r1[i] = j;
r2[i] = j;
if(!c1[j]) c1[j] = i;
c2[j] = i;
} else {
r0[i]++;
c0[j]++;
}
}
}
for(int i=; i<=n; i++) { // 1e3
if(r1[i]!=) {
int t = r1[i]-+m-r2[i];
ans += *r0[i]-t;
}
}
for(int j=; j<=m; j++) { // 1e3
if(c1[j]!=) {
int t = c1[j]-+n-c2[j];
ans += *c0[j]-t;
}
}
cout << ans;
return ;
}

Unfold Code

总结

  这里有一个卡时间的输入数据1000×1000,若只用cin会造成缓冲区超时。缓冲区超时:由于iostream的缓冲跟stdio的同步,导致cin读取速度很慢,用 std::ios::sync_with_stdio(false); 取消同步,加快速度,但是取消了之后,cin不能和stdio的输入(scanf,fscanf, getchar, fgets等)同时使用,不然可能导致输出与预期不一样,另外,cout尽量少加endl,也是防止超时。所以:尽量使用scanf和printf

Codeforces Round #380 (Div. 2) 总结分享的更多相关文章

  1. Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)

    http://codeforces.com/contest/737 A: 题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每 ...

  2. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  3. Codeforces Round #380(div 2)

    A. 题意:给你一串字符串(<=100),将ogo ogogo ogogogo ogogogogo……这种全部缩成***,输出缩后的字符串 分析:第一遍扫对于那些go的位置,记录下next[i] ...

  4. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  5. Codeforces Round #379 (Div. 2) 总结分享

    前言 初入acm的新手,打算在cf混.这几天没有比赛,就做了个最新的Virtual participation.虽然说div2比较简单,但还是被虐得体无完肤...Orz.两个小时,共6道题.最后只AC ...

  6. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心

    E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. Codeforces Round #380 (Div. 2)D. Sea Battle

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 【开发环境】JAVA 环境变量批处理

    @echo off set regpath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environmen ...

  2. CentOS 6 中安装Node.js 4.0 版本或以上

    如果想在CentOS 6 中安装Node.js >4.0,如果通过以往的方式安装: wget http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz t ...

  3. 使用HtmlAgilityPack解析Html(非常好用)

    /// <summary> /// 设计成一个exe,解决WebBrowser控件内存泄漏的问题. /// </summary> public partial class Ma ...

  4. video标签的属性和方法总结

    最近想做一个弹幕插件,查了很多video标签的属性和方法 error属性 在正常读取时候,使用媒体数据的过程中,video元素或audio元素的error属性为null,但是任何时候只要出现错误,er ...

  5. Android 百度云媒体 等播放器播放4:3等多种比例的视频 大小配置的问题

    视频播放宽度大小各不一样,就需要根据视频的尺寸去适应屏幕的宽度和高度进行缩放. 思路是在onPrepared方法中,或者切换屏幕后,获取video的高度和宽度.以及屏幕展示区域的高度的宽度.并对比二者 ...

  6. JS正则表达式验证数字

    <script type="text/javascript"> function validate(){ var reg = new RegExp("^[0- ...

  7. Execution Order of Event Functions

    In Unity scripting, there are a number of event functions that get executed in a predetermined order ...

  8. STL练习题

    //hdu_2717 //map 一对多映射,基于关键字快速查找,不允许重复值 //queue 队列 先进先出 #include<iostream> #include<cstdio& ...

  9. HDU-4869 Turn the pokers

    原题:  Turn the pokers       思路:假设正面为0,反面为1.牌就像这样 000000....... .考虑到假如可以实现最终反面个数为m, 牌共n张, 则这n张排任取m个为反面 ...

  10. 【转】VC中的字符串处理

    http://hi.baidu.com/nmn714/item/ab8d2a96d0f2d6f228164727 貌似不少人刚开始做windows程序时都会纠结在字符串处理上,所以我把关于字符串处理的 ...