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 ...
随机推荐
- 超简单的处理JSON格式和JSON数组格式的String
现在网站上有不少处理JSON格式的工具类,但是我找了一天,发现大都是需要编写相应对象类来进行处理,比较麻烦,比如:Gson,json-lib.Gson,json-lib这些处理那些接口之类的参数名字和 ...
- 局部变量、结构体和main函数
在函数中定义的变量称为自动局部变量.因为每次调用该函数时,它们都自动“创建”,并且它们的只对于函数来说是局部的,局部对象的变量都会默认为空.局部变量的值只能在定义该变量的函数中访问,不能从函数之外访问 ...
- background:transparent的作用
background的属性值 background : background-color | background-image | background-repeat | background-att ...
- 20145211 《Java程序设计》第8周学习总结——自在飞花轻似梦
教材学习内容总结 认识NIO Java NIO(New Input/Output)--新的输入/输出API包--是2002年引入到J2SE 1.4里的.Java NIO的目标是提高Java平台上的I/ ...
- shell 使用for循环 启动后台任务
为了统计多天的数据并按照天为文件名输出,写了脚本,脚本可以统计单天的数据.为了实现多天的同时进行采用 启动多个进程后台执行形式: 但是直接 执行的参数后面加上& 并不能解决,采用 echo & ...
- Java学习-026-类名或方法名应用之二 -- 统计分析基础
前文讲述了类名或方法的应用之一调试源码,具体请参阅:Java学习-025-类名或方法名应用之一 -- 调试源码 此文主要讲述类名或方法应用之二统计分析,通过在各个方法中插桩(调用桩方法),获取方法的调 ...
- imx6 RGB LCD
imx6dl需要支持lcd接口的屏,imx6dl的datasheet并没有明确的说明lcd相关的配置,只在Display Content Integrity Checker (DCIC)一章中介绍.本 ...
- vertical-align的理解
vertical-align的理解 定义和用法 vertical-align 属性设置元素的垂直对齐方式 该属性定义行内元素的基线相对于该元素所在行的基线的垂直对齐 也就是说 它只是个适用行内元素的属 ...
- channelartlist添加栏目链接
{dede:channelartlist} <a href='{dede:field name='typeurl'/}'></a> {/dede:channelartlist}
- Hand 3D Pose Estimation
https://cvarlab.icg.tugraz.at/projects/hand_detection/