题目传送门

 /*
贪心水题:累加到目标数字的距离,两头找取最小值
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
char s[MAXN], t[MAXN]; int main(void) //Codeforces Round #301 (Div. 2) A. Combination Lock
{
//freopen ("A.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
scanf ("%s", &s);
getchar ();
scanf ("%s", &t); int ans = ;
for (int i=; i<n; ++i)
{
int tmp = abs (t[i]-s[i]);
ans += min (tmp, - tmp);
} printf ("%d\n", ans);
} return ;
}

贪心 Codeforces Round #301 (Div. 2) A. Combination Lock的更多相关文章

  1. 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 ...

  2. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...

  3. 贪心 Codeforces Round #109 (Div. 2) B. Combination

    题目传送门 /* 贪心:按照能选的个数和点数降序排序,当条件不符合就break,水题啊! */ #include <cstdio> #include <algorithm> # ...

  4. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

  5. 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know

    题目传送门 /* 题意:从前面找一个数字和末尾数字调换使得变成偶数且为最大 贪心:考虑两种情况:1. 有偶数且比末尾数字大(flag标记):2. 有偶数但都比末尾数字小(x位置标记) 仿照别人写的,再 ...

  6. 贪心 Codeforces Round #297 (Div. 2) C. Ilya and Sticks

    题目传送门 /* 题意:给n个棍子,组成的矩形面积和最大,每根棍子可以-1 贪心:排序后,相邻的进行比较,若可以读入x[p++],然后两两相乘相加就可以了 */ #include <cstdio ...

  7. 贪心 Codeforces Round #304 (Div. 2) B. Soldier and Badges

    题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdi ...

  8. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  9. 找规律/贪心 Codeforces Round #310 (Div. 2) A. Case of the Zeros and Ones

    题目传送门 /* 找规律/贪心:ans = n - 01匹配的总数,水 */ #include <cstdio> #include <iostream> #include &l ...

随机推荐

  1. Emag eht htiw Em Pleh(imitate)

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2901   Accepted:  ...

  2. 用LoadRunner实现接口测试

    接口测试的两种方法 其实无论用那种测试方法,接口测试的原理是通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一个过 ...

  3. Eighth scrum meeting - 2015/11/2

    由于之前的在线视频播放控件功能过于简单,我们今天从网上找了一个效果还不错的视频播放开源项目,在添加了复杂的依赖后终于能够正常使用了,效果比起之前来也好了很多,而且后续的视频下载功能也可以基于这个来开发 ...

  4. HDU 1025 Constructing Roads In JGShining's Kingdom(求最长上升子序列nlogn算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p ...

  5. opencv中,c和c++版本区别体验

    参考:http://www.cnblogs.com/tornadomeet/archive/2012/04/29/2476277.html

  6. ZeroMQ(java)之负载均衡

    我们在实际的应用中最常遇到的场景如下: A向B发送请求,B向A返回结果.... 但是这种场景就会很容易变成这个样子: 很多A向B发送请求,所以B要不断的处理这些请求,所以就会很容易想到对B进行扩展,由 ...

  7. 浅析django的abstract,proxy, managed

    django.db.models.Model 的 Meta参数 参数 类型 说明 继承 abstract boolean 是否建表 不继承,子类自动充值为默认值(False) managed bool ...

  8. Ubuntu14.04server开放rootssh登录权限

    刚安装了Ubuntu 14.04 server的虚拟机,普通帐号可以远程登录,但是root不行,输入密码后一直报错: permission denied 最后发现ssh的配置(/etc/ssh/ssh ...

  9. InnoDB主键设计

    InnoDB是clustered-index table,因此对于InnoDB而言,主键具有特殊意义. 可以通过主键直接定位到对应的某一数据行记录的物理位置,主键索引指向对应行记录,其他索引则都指向主 ...

  10. First Position of Target

    For a given sorted array (ascending order) and a target number, find the first index of this number ...