题目列表:

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. noip 2009 细胞分裂

    /*数论题 考察唯一分解定理 当然用到一些技巧*/ #include<iostream> #include<cstdio> #include<cstring> #d ...

  2. 在Github上面搭建Hexo博客(一):部署到Github

    什么是Hexo Hexo是一个基于Node.js的静态博客程序,可以方便的生成静态网页托管在Github和Heroku上.并且有很多人为其制作了很多优秀的主题(theme),你可以根据自己的喜好进行设 ...

  3. boostrap按钮

    bootstrap按钮 对应链接:http://v3.bootcss.com/css/#buttons 使用时添加基础类class:btn 默认样式class=btn-default,控制大小clas ...

  4. CSS3 target 伪类不得不说那些事儿(纯CSS实现tab切换)

    是不是觉得target有点眼熟?! 今天要讲的不是HTML的<a>标签里面有个target属性. target伪类是css3的新属性. 说到伪类,对css属性的人肯定都知道:hover.: ...

  5. GridView and DropDownList

    <form id="form1" runat="server"> <div> <asp:GridView runat=" ...

  6. iOS中使用图片作为颜色的背景图

    Objective-C: [UIColor colorWithPatternImage:[UIImage imageNamed:@"jpg"]]; Swift: UIColor(p ...

  7. oracle 语句

    1.查询TRENDCHART_DLT表中的30条数据,统计字段FRONT01='0',BACK12='0'的条数 select sum(case when FRONT01='0' then 1 els ...

  8. 武汉科技大学ACM:1010: 零起点学算法27——判断是否直角三角形

    Problem Description 输入三个整数,分别代表三角形的三条边长度,判断能否构成直角三角形 Input 输入3个整数a,b,c(多组数据,-5000000<a,b,c<500 ...

  9. C++拾遗(九)类与动态内存分配(1)

    创建类时编译器自动生成以下成员函数(如果用户没有定义): 1.默认构造函数 2.拷贝构造函数 3.赋值操作符 4.默认析构函数 5.地址操作符 以下一一说明: 构造函数 构造函数在创建对象时被调用. ...

  10. Canvas前端游戏开发——FlappyBird详解

    一直想自己做点小东西,直到最近看了本<HTML5游戏开发>,才了解游戏开发中的一点点入门知识. 本篇就针对学习的几个样例,自己动手实践,做了个FlappyBird,源码共享在度盘;也可以参 ...