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 ...
随机推荐
- java FileWriter and FileReader
import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class FWFRD ...
- 有序列表和无序列表、流、格式布局:position
列表方块: 有序列表和无序列表 ol/ul 例如<ol: style:"list-style:"" "> 1.<ol: style:&quo ...
- php--yii2.0框架的curl
yii2.0框架的增删改查 //插入操作 save() $customer=new Customer(); $customer->name=‘小熊‘; $customer->save() ...
- 设计模式:工厂方法模式(Factory Method)
定义:定义一个用于创建对象的接口,让子类决定实例化哪一个类. 工厂方法使一个类的实例化延迟到其子类. 结构图: 示例: HTML代码: <html xmlns="http://www. ...
- Win7局域网文件共享方法
右击桌面网络----属性----更改高级共享设置 (注释:查看当前网络 比如:家庭网络.公共网络 等!) "我这里为公共网络" 选择 公共网络---选择以下选项:启动网络发 ...
- Android调用WCF
http://www.cnblogs.com/davidgu/archive/2012/05/16/2504182.html
- <dependency>spring-webmvc</dependency>
Spring 4.2.0.RELEASE版本: <dependency> <groupId>org.springframework</groupId> <ar ...
- java.lang.IllegalArgumentException: No converter found for return value of type: class Person
在http://www.cnblogs.com/winner-0715/p/6033462.html我们讲到三个条件就能实现SpringMVC返回json的功能 但是按照这三个条件配置后,运行出现了错 ...
- ubuntu14.04安装Docker
Ubuntu在14.02开始就已经集成了Docker,要安装很简单: 1 2 3 4 sudo apt-get update sudo apt-get install docker.io sudo ...
- OpenGL-选择与拾取
转自:http://blog.sina.com.cn/s/blog_4a9aa55c0100vu57.html 以下内容主要整理<OpenGL编程指南>第13章的内容.主要解决以下问题: ...