USACO: Combination Lock
长久不写算法题,这种简单题折腾了一下午。。。
/*
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的更多相关文章
- 洛谷 P2693 [USACO1.3]号码锁 Combination Lock
P2693 [USACO1.3]号码锁 Combination Lock 题目描述 农夫约翰的奶牛不停地从他的农场中逃出来,导致了很多损害.为了防止它们再逃出来,他买了一只很大的号码锁以防止奶牛们打开 ...
- Combination Lock
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...
- hihocoder #1058 Combination Lock
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...
- 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock
题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...
- 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 ...
- Hiho----微软笔试题《Combination Lock》
Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...
- CF #301 A :Combination Lock(简单循环)
A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:
- hihocoder-第六十一周 Combination Lock
题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...
- A - Combination Lock
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Scroog ...
随机推荐
- url匹配和match()方法
下面的全局匹配可以找到字符串中的所有数字: "1 plus 2 equals 3".match(/\d+/g) // 返回 ["1", "2" ...
- java JDK8 学习笔记——第11章 线程和并行API
第11章 线程与并行API 11.1 线程 11.1.1 线程 在java中,如果想在main()以外独立设计流程,可以撰写类操作java.lang.Runnable接口,流程的进入点是操作在run( ...
- Qt 无边框窗体改变大小 完美实现(全部自己实现)
近期,做项目用到无边框窗体,令人蛋疼的是无边框窗体大小的改变要像右边框那样,上下左右四周,而且要流畅. 网上也找了些代码,发现居然还要连接到windows事件,这显然不合常理,后来自己新建了demo, ...
- Nodejs电影建站开发实例(下)
作为一个真正的网站,不能没有数据的支持,下面使用的数据库为mongodb,电影可能有的数据:电影名称.导演.国家.语言.上映时间.图片.简介.视频 4.使用路由 app.js var express ...
- Maven实战(三)Eclipse构建Maven项目
1. 安装m2eclipse插件 要用Eclipse构建Maven项目,我们需要先安装meeclipse插件 点击eclipse菜单栏Help->Eclipse Marketplac ...
- EF不同查询方法生成的SQL比较
var test1 = db.jj_RolesItem.Join(db.jj_SysItemsClass, m => m.ClassID, g => g.ClassID, (m, g) = ...
- iOS 隐藏Status Bar
要隐藏,有3个地方要做: 1.在info.Plist里,将该属性的hidden,设置为YES,这样,在启动时,就不会显示了: 2.在application-didFinish里面写,这样,可以隐藏io ...
- iOS GCD简单使用
Grand Central Dispatch (GCD) 1)运行在主线程的Main queue,通过dispatch_get_main_queue获取. /*!* @function dispatc ...
- How to read the HTML DTD
Contents How to read the HTML DTD 1. DTD Comments 2. Parameter Entity definitions 3. Element declara ...
- 简述Docker镜像、容器、仓库概念
Docker镜像 Docker镜像(Image)类似于虚拟机的镜像,可以将他理解为一个面向Docker引擎的只读模板,包含了文件系统. 例如:一个镜像可以完全包含了Ubuntu操作系统环境,可以把它称 ...