长久不写算法题,这种简单题折腾了一下午。。。

 /*
 ID: yingzho2
 LANG: C++
 TASK: combo
 */
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <map>
 #include <vector>
 #include <set>
 #include <algorithm>
 #include <stdio.h>
 #include <queue>
 #include <cstring>
 #include <cmath>
 #include <list>
 #include <cstdio>
 #include <cstdlib>
 #include <limits>
 #include <stack>

 using namespace std;

 ifstream fin("combo.in");
 ofstream fout("combo.out");

 int dis(int N, int a, int b) {
     if (a > b) swap(a, b);
     return min(b-a, N-b+a);
 }

 int main()
 {
     int N;
     ], b[];
     fin >> N;
     ; i < ; i++) fin >> a[i];
     ; i < ; i++) fin >> b[i];
     , N)*min(, N)*min(, N)*;
     ;
     bool flag = false;
     ; i < ; i++) {
         ) {
             sum *= N;
             flag = true;
         }
         ) {
             sum *= ( - dis(N, a[i], b[i]));
             flag = true;
         }
     }
     if (flag) ans -= sum;
     fout << ans << endl;
     ;
 }

USACO: Combination Lock的更多相关文章

  1. 洛谷 P2693 [USACO1.3]号码锁 Combination Lock

    P2693 [USACO1.3]号码锁 Combination Lock 题目描述 农夫约翰的奶牛不停地从他的农场中逃出来,导致了很多损害.为了防止它们再逃出来,他买了一只很大的号码锁以防止奶牛们打开 ...

  2. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  3. hihocoder #1058 Combination Lock

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...

  4. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

  5. Codeforces Round #301 (Div. 2) A. Combination Lock 暴力

    A. Combination Lock Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...

  6. Hiho----微软笔试题《Combination Lock》

    Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...

  7. CF #301 A :Combination Lock(简单循环)

    A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:

  8. hihocoder-第六十一周 Combination Lock

    题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...

  9. A - Combination Lock

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Scroog ...

随机推荐

  1. php经典笔试题

    五.基础及程序题(建议使用你擅长的语言:C/C++.PHP.Java) 5.写一个排序算法,可以是冒泡排序或者是快速排序,假设待排序对象是一个维数组.(提示:不能使用系统已有函数,另外请仔细回忆以前学 ...

  2. 蓝牙Bluetooth技术手册规范下载

    [背景] 之前就已经整理和转帖了和蓝牙技术相关的一些内容: [资源下载]bluetooth 协议 spec specification 蓝牙1.1.蓝牙1.2.蓝牙2.0(蓝牙2.0+EDR)区别 但 ...

  3. vs2013 RTM 激活码

    BWG7X-J98B3-W34RT-33B3R-JVYW9

  4. Redis学习笔记--五种数据类型的使用场景

    String 1.String 常用命令: 除了get.set.incr.decr mget等操作外,Redis还提供了下面一些操作: 获取字符串长度 往字符串append内容 设置和获取字符串的某一 ...

  5. 对象(List<T>)的序列化和反序列化

    本文描述将对象(List<T>)序列化到 XML 文档中和从 XML 文档中反序列化为对象(List<T>). 命名空间: System.Xml.Serialization 程 ...

  6. QDir路径的测试与创建-QT

    #include <QCoreApplication> #include <QDir> #include<QtDebug > #include<QFileIn ...

  7. PMP--论文部分

    个人观点,是三个部分最简单,最容易复习的,当然,如果你没有做好一个项目的摘要和正文的背诵,连各个过程的工具输输入输出的都记不住几个,就不用往下看了,以上内容的观点,至少保证真题做三次以上,书籍教材看三 ...

  8. Progress Reporting

    Progress reporting is a key activity of project management. The project manager issues regular repor ...

  9. Selenium2学习-035-WebUI自动化实战实例-033-页面快照截图应用之三 -- 区域截图(专业版)

    之前有写过两篇博文讲述了 WebUI 自动化测试脚本中常用的截图方法,敬请参阅如下所示链接: 浏览器显示区域截图 浏览器指定区域截图 那么当需要截取的区域不在浏览器显示窗口范围之内时,之前的方法显然无 ...

  10. http://blog.csdn.net/yunhua_lee/article/details/52710894

    http://blog.csdn.net/yunhua_lee/article/details/52710894