题目列表:

2146 Problem A 【手速】阔绰的Dim
2147 Problem B 【手速】颓废的Dim
2148 Problem C 【手速】我的滑板鞋
2149 Problem D 【手速】潦倒的Dim
2150 Problem E 【手速】被NTR的Dim

2146 Problem A:

简单的最长回文串统计算法,这里没有过高要求,n^2算法可以AC。其中包括dp动规以及中心法(以上两种都是O(n^2)算法,可以参考白书)。推广,可以尝试扩展KMP(O(nlogn))或者Manacher算法(O(n))。可以查阅相关资料自行选择学习。这里给出中心法。

 /****************************************/
/***** Desgard_Duan *****/
/****************************************/
//#pragma comment(linker, "/STACK:102400000,102400000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> using namespace std; char s[]; int len; inline void get_val(int &a) {
int value = , s = ;
char c;
while ((c = getchar()) == ' ' || c == '\n');
if (c == '-') s = -s; else value = c - ;
while ((c = getchar()) >= '' && c <= '')
value = value * + c - ;
a = s * value;
} int tofind(int h, int t) {
int re = t - h + ;
while (h < t) {
if (s[h++] != s[t--]) return ;
}
return re;
} int main() {
//freopen("huiwen.in", "r", stdin);
//freopen("huiwen.out","w",stdout);
int T;
cin >> T;
while (T--) {
scanf("%s", s);
len = strlen(s);
int ans = ;
for (int i = ; i < len - ; i++)
for (int j = i + ; j < len; j++) {
ans = max(ans, tofind(i, j));
}
cout << ans << endl;
}
return ;
}

2147 Problem B:

一道字符串水题,只要按位置遍历一遍即可。C语言基础题。

 /****************************************/
/***** Desgard_Duan *****/
/****************************************/
//#pragma comment(linker, "/STACK:102400000,102400000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> using namespace std; inline void get_val(int &a) {
int value = , s = ;
char c;
while ((c = getchar()) == ' ' || c == '\n');
if (c == '-') s = -s;
else value = c - ;
while ((c = getchar()) >= '' && c <= '')
value = value * + c - ;
a = s * value;
} string str1, str2;
int main () {
int T;
//cin >> T;
while (cin >> str1 >> str2) { int ans = ;
for (int i = ; i < str1.size(); ++ i) {
if (str1[i] == str2[i]) {
ans ++;
}
}
cout << ans << endl;
}
return ;
}

2148 Problem C:

一道贪心的白书例题,类型归类为查找不相交区间的最大个数。具体思路:对于相交的任意两个区间分为两种情况(图A、图B)。若出现情况A,直接将大区间删除即可。若出现情况B,我们先将集合按照x进行升序排列,然后优先选取x最小的情况B中的区间,这样可以得到最佳的方案。

 /****************************************/
/***** Desgard_Duan *****/
/****************************************/
//#pragma comment(linker, "/STACK:102400000,102400000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> using namespace std; inline void get_val(int &a) {
int value = , s = ;
char c;
while ((c = getchar()) == ' ' || c == '\n');
if (c == '-') s = -s;
else value = c - ;
while ((c = getchar()) >= '' && c <= '')
value = value * + c - ;
a = s * value;
} vector<pair<int, int> > shoes;
bool flag[]; int main () {
int n, x, y;
//freopen("out.txt", "w", stdout);
while (~scanf ("%d", &n)) {
shoes.clear();
for (int i = ; i < n; ++ i) {
cin >> x >> y;
shoes.push_back (make_pair(x, y));
}
sort (shoes.begin(), shoes.end()); memset (flag, , sizeof (flag));
for (int i = ; i < n; ++ i) {
if (flag[i]) {
continue;
}
for (int j = ; j < n; ++ j) {
if (i == j) continue;
else {
if (shoes[i].first <= shoes[j].first && shoes[i].second >= shoes[j].second) {
flag[i] = ;
}
}
}
}
int cur = , ans = ;
for (; cur < shoes.size() && flag[cur]; cur ++);
int last_end = shoes[cur].second, this_begin;
for (int i = cur + ; i < shoes.size(); ++ i) {
if (flag[i]) continue;
this_begin = shoes[i].first;
if (last_end <= this_begin) {
ans ++;
last_end = shoes[i].second;
}
}
cout << ans << endl; }
return ;
}

2149 Problem D:

一道大数题目。在n个大数中寻找最小的数。大数推荐使用Java大数类,相对来说代码比较清晰。也可以直接开一个数组进行模拟。

 import java.math.*;
import java.io.*;
import java.util.*; public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
BigInteger ans = BigInteger.ZERO;
for (int i = 0; i < n; ++i) {
BigInteger a = in.nextBigInteger();
if (i == 0) {
ans = a;
} else {
ans = ans.min(a);
}
}
System.out.println (ans);
}
}
}

2150 Problem E:

一道简单的数学题目。稍微推导一下就会发现这个函数最多只有六项。分别是a, b, b - a, -a, -b, a - b六个数,只要我们去一下重复的数即可。去重方法可以用一个字符串数组来做,这里用了set容器的性质进行了去重操作。

 /****************************************/
/***** Desgard_Duan *****/
/****************************************/
//#pragma comment(linker, "/STACK:102400000,102400000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> using namespace std; inline void get_val(int &a) {
int value = , s = ;
char c;
while ((c = getchar()) == ' ' || c == '\n');
if (c == '-') s = -s;
else value = c - ;
while ((c = getchar()) >= '' && c <= '')
value = value * + c - ;
a = s * value;
} int a, b, n;
set<int> S;
int main () {
while (cin >> a >> b >> n) {
S.clear();
if (n >= ) {
S.insert (a);
S.insert (b);
S.insert (b - a);
S.insert (-a);
S.insert (-b);
S.insert (a - b);
cout << S.size() << endl;
continue;
} else {
int last = a, now = b, t;
S.insert (a);
S.insert (b);
for (int i = ; i <= n; ++ i) {
S.insert (now - last);
t = now;
now = now - last;
last = t;
}
cout << S.size() << endl;
}
}
return ;
}

最后,感谢这次的命题者:王浩宇(stdiohero),叶鹏(yeahpeng),王驰(wid),谢文亮(Dim),朱吴帅(JM)同学为我们出的这套热身题目。祝大家在参赛后有所提高。谢谢大家。

——Desgard_Duan

2014.10.31

Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)的更多相关文章

  1. 2018.10.19浪在ACM 集训队第一次测试赛

    2018.10.19浪在ACM 集训队第一次测试赛 待参考资料: [1]:https://blog.csdn.net/XLno_name/article/details/78559973?utm_so ...

  2. Known Notation括号匹配类问题(2014年ACM/ICPC 亚洲区域赛牡丹江)

    题意: 给你数字或 * 的串,你可以交换一个*和数字.在最前面添1.在一个地方插入*,问你使串满足入栈出栈的(RNP)运算法则. 思路: 引用:https://blog.csdn.net/u01158 ...

  3. 2018.10.26 浪在ACM 集训队第四次测试赛

    2018.10.26 浪在ACM 集训队第四次测试赛 题目一览表 来源 考察知识点 完成时间 A 生活大爆炸版 石头剪刀布  NOIP 提高组 2014   模拟???  2018.11.9 B 联合 ...

  4. 2018.10.2浪在ACM 集训队第三次测试赛

    2018.10.26 浪在ACM 集训队第三次测试赛 今天是暴力场吗???????可怕 题目一览表 来源 考察知识点 完成时间 A 1275 珠心算测试 NOIP 普及组 2014 暴力??? 201 ...

  5. 2018.12.21 浪在ACM 集训队第十次测试赛

     浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...

  6. 2018.12.14 浪在ACM 集训队第九次测试赛

    浪在ACM 集训队第九次测试赛 B Battleship E Masha and two friends B 传送门 题意: 战船上有占地n*n的房间cells[][],只由当cells[i][j]= ...

  7. 2018.10.2浪在ACM 集训队第二次测试赛

    2018.10.26 浪在ACM 集训队第二次测试赛 题目一览表 来源 考察知识点 A 1273 海港 NOIP 普及组 2016 差分数组+二分 B 1274 魔法阵     C 1267 金币   ...

  8. 2018.12.7 浪在ACM 集训队第八次测试赛

    2018.12.7 浪在ACM 集训队第八次测试赛  https://blog.csdn.net/QLU_minoz/article/details/84886717   感谢苗学林同学C题和D题题解 ...

  9. 2018.11.23 浪在ACM 集训队第六次测试赛

    2018.11.23 浪在ACM 集训队第六次测试赛 整理人:刘文胜 div 2: A: Jam的计数法 参考博客:[1] 万众 B:数列 参考博客: [1] C:摆花 参考博客: [1] D:文化之 ...

随机推荐

  1. 动态规划+滚动数组 -- POJ 1159 Palindrome

    给一字符串,问最少加几个字符能够让它成为回文串. 比方 Ab3bd 最少须要两个字符能够成为回文串 dAb3bAd 思路: 动态规划 DP[i][j] 意味着从 i 到 j 这段字符变为回文串最少要几 ...

  2. JBoss 系列九十九:Rest WebService jBPM 6 集成演示样例

    概述 jBPM 6 提供 Rest API 供第三方应用整合使用 jBPM 6,本文演示假设通过 Rest API: 启动流程 获取流程实例信息 启动 User Task 完毕 User Task j ...

  3. C#获取文件夹下指定格式的所有文件

    C#获取文件夹下指定格式的所有文件的方法,虽然很简单,但还是分享一下吧,用到时可以稍加修改和优化就可以使用. 获取指定目录下所有文件 //最要使用 System.IO.Directory.GetFil ...

  4. poj 1328 贪心

    /* 贪心.... 处理处每个点按照最大距离在x轴上的映射 然后我们就有了一些线段 目的是选取尽量少的点 使得每个线段内都有点出现 我们按照左端点排序 然后逐一处理 假设第一个雷达安在第一个线段的右端 ...

  5. ZOJ3161

    朴素动态规划 ZOJ3161 题意:(严重标题党)老板不想让客人走,客人不想留,客人按顺序排好,老板抽8g(书上翻译成八卦,神翻译),抽到的 如果相邻,其中一个人由客人决定离开,求最后黑心的老板最多能 ...

  6. (转)html5 Placeholder属性兼容IE6、7方法

    使低版本浏览器支持Placeholder有很多方法,都不是很完美,或多或少有点问题,且有些原生支持的浏览器在获得焦点时会清空Placeholder提示.发现zhihu的解决方法不错,特记录下 wind ...

  7. 关于slideup和slidedown 鼠标多次滑过累积的动画效果

    stop() 方法停止当前正在运行的动画 包括animation动画和slideup/slidedown动画 例如:鼠标经过一个元素时,执行一个slide动画,多次快速经过,不处理的话这个元素会保留累 ...

  8. (转)CentOS下用yum搭建LNMP服务器

    原文链接:http://www.xiaohuai.com/2733 CentOS下搭服务器也折腾好几次了, 每次都知道个大概, 具体repo的地址什么的还都要现找, 实在不效率, 干脆整理记录下来. ...

  9. (转,感谢原作者!)既然选择了Linux,有何必在乎这些——Linux wine国服LOL英雄联盟,完美运行!!

    Linux下玩国服LOL,国服哦.网络上随处都可以搜到wine美服LOL的教程,但腾讯运营的国服客户端跟美服原版相差比较大,按照美服的方式不能搞起国服LOL,由于宿舍文化,这几天我专注于wine一个国 ...

  10. Oracle数据库之数据类型

    Oracle数据库之数据类型 Oracle基本数据类型(亦叫内置数据类型,internal datatypes或built-in datatypes)可以按类型分为:字符串类型.数字类型.日期类型.L ...