Codeforces Round #293 (Div. 2)
题意:两个字符串s,t,是否存在满足:s < r < t 的r字符串
字符转处理:字典序排序
很巧妙的方法,因为s < t,只要找比t字典序稍微小一点的和s比较就行了
具体方法和数字减1相类似,从"个位"减1,如果是0,从前面借1
!strcmp (t, s):如果t < s 或者 t > s (不可能)则输出,t == s 则输出NO
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
using namespace std; const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f; int main(void)
{
//freopen ("A.in", "r", stdin); char s[110], t[110]; while (~scanf ("%s %s", &s, &t))
{
int cnt = strlen (s) - 1;
while (t[cnt] == 'a' && cnt >= 0)
{
t[cnt] = 'z';
cnt--;
}
t[cnt]--;
(!strcmp (t, s)) ? puts ("No such string") : printf ("%s\n", t);
} return 0;
}
字符串处理:字符查找
记录s,t各自的大小写字母的数量,然后累加完全匹配的cnty和不完全匹配的cntw
这道题题目我没读懂,cntw不完全匹配意思是:只是大小不相同
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <set>
using namespace std; const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f; int main(void)
{
//freopen ("B.in", "r", stdin); char s[MAXN], t[MAXN];
int m1[30], m2[30], m3[30], m4[30]; while (cin >> s >> t)
{
memset (m1, 0, sizeof (m1));
memset (m2, 0, sizeof (m2));
memset (m3, 0, sizeof (m3));
memset (m4, 0, sizeof (m4));
for (int i=0; s[i]!='\0'; ++i)
{
if (s[i]>='a' && s[i]<='z')
m1[s[i] - 'a']++;
else
m2[s[i]-'A']++;
}
for (int i=0; t[i]!='\0'; ++i)
{
if (t[i]>='a' && t[i]<='z')
m3[t[i] - 'a']++;
else
m4[t[i]-'A']++;
}
int cnty = 0, cntw = 0;
for (int i=0; i<26; ++i)
{
int d = min (m1[i], m3[i]);
m1[i] -= d;
m3[i] -= d;
cnty += d;
d = min (m2[i], m4[i]);
m2[i] -= d;
m4[i] -= d;
cnty += d;
}
for (int i=0; i<26; ++i)
{
int d = min (m1[i], m4[i]);
m1[i] -= d;
m4[i] -= d;
cntw += d;
d = min (m2[i], m3[i]);
m2[i] -= d;
m3[i] -= d;
cntw += d;
} cout << cnty << " " << cntw << endl;
} return 0;
}
无算法
统计划屏的次数,如果在第一屏则不用,只要每次交换与前面数字的顺序就行了
注意:ans开long long
好吧,这道题是最水的,主要是题目很难读懂,可以从Note里猜出题目意思
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
using namespace std; const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f; int num[MAXN];
int pos[MAXN]; int main(void)
{
//freopen ("C.in", "r", stdin); int n, m, k; while (~scanf ("%d%d%d", &n, &m, &k))
{
int x;
for (int i=1; i<=n; ++i)
{
scanf ("%d", &x);
pos[x] = i;
num[i] = x;
}
long long ans = 0;
for (int i=1; i<=m; ++i)
{
scanf ("%d", &x); int p = pos[x];
ans += (p / k);
if (p % k) ans += 1;
if (p == 1) continue; int y = num[p-1];
num[p-1] = x;
num[p] = y;
pos[y]++; pos[x]--;
} printf ("%I64d\n", ans);
} return 0;
}
Codeforces Round #293 (Div. 2)的更多相关文章
- Codeforces Round #293 (Div. 2) D. Ilya and Escalator 概率DP
D. Ilya and Escalator time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #293 (Div. 2) C. Anya and Smartphone 数学题
C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard 水题
B. Tanya and Postcard time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #293 (Div. 2) A. Vitaly and Strings
A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- hdu.5203.Rikka with wood sticks(数学推导:一条长度为L的线段经分割后可以构成几种三角形)
Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- rubycas-client单点登录
(文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 进行中,未完待续 Ruby 客户端 使用方法0. 在 Gemfile中,加入: gem 'rubyc ...
- Coursera台大机器学习课程笔记3 – 机器学习的分类和机器学习的可能性
第三讲比较简单,参考:http://www.cnblogs.com/HappyAngel/p/3466527.html 第四讲很抽象,尤其是第四个视频,目的仍然是为了证明机器学习是可能的,不过这个博主 ...
- javascript memoization递归优化
memoize优化递归 function createRec(callback, cache) { cache = cache || []; var rec = function(n) { (n in ...
- BZOJ 1452 [JSOI2009] Count
这道题好像有点简单的样子... absi找题目好厉害啊...确实是一道比较裸的2dBIT啊. 水掉吧. 附:2dBIT怎么做: 2dBIT就是BIT套BIT啦. 所以修改loop(x+=lowbit( ...
- 右移>> 和 左移<<
一个int占四个字节,也就是32位,这样的话1不论左移还是右移32位仍旧移到原来的位置,就仍旧是1了. 右移是除,左移是乘.1除1除32次和1乘1乘32次当然都还是1了. 移位操作的简单计算方法 &g ...
- 夏令时 DST (Daylight Saving Time) java中的夏令时【转】
1916年,德国首先实行夏令时,英国因为怕德国会从中得到更大的效益,因此紧跟着也采取了夏令时 1986年至1991年,中华人民共和国在全国范围实行了六年夏令时 サマータイム 夏時間(日本现在没有实行夏 ...
- 《ASP.NET MVC4 WEB编程》学习笔记------Entity Framework的Database First、Model First和Code Only三种开发模式
作者:张博出处:http://yilin.cnblogs.com Entity Framework支持Database First.Model First和Code Only三种开发模式,各模式的开发 ...
- sharepoint更新多行文本webparth
前台 <script> function Copy() { var value = document.getElementById("<%=BodyBox.ClientID ...
- PHP 转换接口编码
2014年10月20日 10:45:19 有些时候调用接口的时候返回数据的编码不是utf-8的,需要转码 foreach ($arrInfo as $k => $v) { $encodeing ...