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

 /*
 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. TM2013修改帐号数据目录

    M 2013安装以后,聊天记录文件夹默认的保存位置是在“我的文档”中“Tencent Files”,而QQ就可以在软件系统设置中进行指定,但TM2013没有这一栏设置,那么如何才能修改聊天记录文件夹保 ...

  2. pro10

    1.本次课学习到的知识点: 什么是数组?为什么要使用数组?如何定义数组? 如何引用数组元素? 2. 实验过程中遇到的问题及解决方法: 在最后一个试验中,在输出最大小标那里进行了仔细的思考,刚开始思考应 ...

  3. JavaScript POST 请求如何跨域

    前天遇到一个问题,就是我上传图片的时候,这个图片需要上传给某个API的接口 这样问题就来了,我们之前上传图片的时候都是先上传到我们自己的后台里面,然后通过后台,再把这个流传到图片服务器上. 但是上传到 ...

  4. javaScript没有块级作用域

    1.如下,变量i,j,k 的作用域是相同的. function test(obj){ var i= 0; if(typeof obj == "object"){ var j = 0 ...

  5. WPF自定义RoutedEvent事件示例代码

    ************************* 引用网友,便于查找所用..... 创建自定义路由事件和应用分为6个步骤: (1)自定义路由事件参数对象 (2)声明并注册路由事件 (3)为路由事件添 ...

  6. Tram---poj1847(简单最短路)

    题目链接:http://poj.org/problem?id=1847 题意:给了N个交叉口,每个交叉口有自己能转到的交叉口. 注意这里:First number in the i-th line, ...

  7. Linq To Sql多表联合查询

    var pro = (from ps in db.ProductInfoes join pt in db.ProductTypees on ps.productType equals pt.pType ...

  8. 内置对象Global和Math对象

    Global对象Math对象 1.Global对象Global.属性方法或者Global.方法()是无效的,web浏览器将Global作为window对象的一部分加一实现.uri编码——了解2.eva ...

  9. [BS-24] UIImageView的contentMode属性

    UIImageView的contentMode属性   所有的UIView都有个contentMode属性,UIImageView继承自UIView,我们在使用UIImageView时,经常要考虑这些 ...

  10. SpringMVC Map Model ModelMap 和 ModelAndView

    代码: package com.gaussic.controller; import com.gaussic.model.AccountModel; import org.springframewor ...