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 ...
随机推荐
- editplus快捷键大全之editplus光标快捷键
前面我们讲了editplus快捷键大全之editplus文件快捷键,现在我们介绍一下editplus快捷键大全之editplus光标快捷键 移动光标到上一个制表符Shift+Tab 移动光标到上一个制 ...
- Excel导入导出,生成和下载Excel报表、附件等操作--ASP.NET
public class OutExcel { public static void OutExcel_bb(DataTable dt, string thepath, string temppath ...
- Android EditText 文本框实现搜索和清空效果
前言 本文实现的效果:文本框输入为空时显示输入的图标:不为空时显示清空的图标,此时点击清空图标能清空文本框内输入文字. 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnbl ...
- Unity3D占用内存太大的解决方法
原地址:http://www.cnblogs.com/88999660/archive/2013/03/15/2961663.html 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大 ...
- 对于(function(){}())和function(){}实例的作用域分析(里面有很多问题……)
今天在群里看到一个问题,让我纠结了好一会.下面是我的分析,感觉里面还有很多问题,关于作用域还是不太理解,希望大家看到问题第一时间反馈给我,看到实在受不了的地方说几句都没关系,谢谢. 请看题: 1.对象 ...
- ZeroMQ(java)中监控Socket
基本上ZeroMQ(java)中基本的代码都算是过了一遍了吧,不过觉得它在日志这一块貌似基本没有做什么工作,也就是我们通过日志来知道ZeroMQ都发生了什么事情.. 而且由于ZeroMQ中将连接的建立 ...
- Linux下tomcat服务
一:Linux下tomcat服务的启动.关闭与错误跟踪,使用PuTTy远程连接到服务器以后,通常通过以下几种方式启动关闭tomcat服务:切换到tomcat主目录下的bin目录(cd usr/loca ...
- Nmap备忘单:从探索到漏洞利用(Part3)
众所周知NMAP是经常用来进行端口发现.端口识别.除此之外我们还可以通过NMAP的NSE脚本做很多事情,比如邮件指纹识别,检索WHOIS记录,使用UDP服务等. 发现地理位置 Gorjan Petro ...
- div设置边框黑框显示
style="width:756px; height:68px; border:1px solid #000000;"
- Java异常与异常处理简单使用
异常就是程序运行过程中阻止当前方法或作用域继续执行的问题: 任何程序都不能保证完全正常运行,当发生异常时,需要我们去处理异常,特别是一些比较重要的场景,异常处理的逻辑也会比较复杂,比如:给用户提示.保 ...