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 ...
随机推荐
- 最近打算体验一下discuz,有不错的结构化数据插件
提交sitemap是每位站长必做的事情,但是提交到哪里,能不能提交又是另外一回事.国内的话百度是大伙都会盯的蛋糕,BD站长工具也会去注册的,可有些账号sitemap模块一直不能用,或许是等级不够,就像 ...
- MFC 中控件的启用与禁用
启用和禁用控件可以调用CWnd::EnableWindow 函数. BOOL EnableWindow(BOOL bEnable = TRUE); 判断控件是否可用可以调用 CWnd::IsWindo ...
- iPhone取消软件更新上边的1
去除设置的更新+1小红点提示主要分为越狱和非越狱设备两种方法. 越狱状态下方法: 首先将你的设备进行越狱: 越狱后安装ifile(这个自行搜索安装): 用ifile打开/System/Library/ ...
- How to: Set up Openswan L2TP VPN Server on CentOS 6
Have you ever wanted to set up your own VPN server? By following the steps below, you can set up you ...
- MySQL使用索引的场景及真正利用索引的SQL类型
1. 为什么使用索引 在无索引的情况下,MySQL会扫描整张表来查找符合sql条件的记录,其时间开销与表中数据量呈正相关.对关系型数据表中的某些字段建索引可以极大提高查询速度(当然,不同字段是否sel ...
- linux下创建库函数
来源: 在Linux下如何使用自己的库函数-riverok-ChinaUnix博客 http://blog.chinaunix.net/uid-21393885-id-88128.html 构建Lin ...
- UEditor去除复制样式实现无格式粘贴
UEditor内置了无格式粘贴的功能,只需要简单的配置即可. 1.修改ueditor.config.js,开启retainOnlyLabelPasted,并设置为true 2.开启pasteplain ...
- codeforces 488A. Giga Tower 解题报告
题目链接:http://codeforces.com/problemset/problem/488/A 题目意思:给出一个数a,范围是[-10^9, 10^9],问它最少需要加的一个正整数 b 是多少 ...
- 关于printf函数输出先后顺序的讲解!!
对于printf函数printf("%d%d\n",a,b);函数的实际输出顺序是这样的先计算出b,然后在计算a,接着输出a,最后在输出b:例子如下:#include<ios ...
- Linux内核同步机制之(二):Per-CPU变量
转自:http://www.wowotech.net/linux_kenrel/per-cpu.html 一.源由:为何引入Per-CPU变量? 1.lock bus带来的性能问题 在ARM平台上,A ...