Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)
题目列表:
| 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)的更多相关文章
- 2018.10.19浪在ACM 集训队第一次测试赛
2018.10.19浪在ACM 集训队第一次测试赛 待参考资料: [1]:https://blog.csdn.net/XLno_name/article/details/78559973?utm_so ...
- Known Notation括号匹配类问题(2014年ACM/ICPC 亚洲区域赛牡丹江)
题意: 给你数字或 * 的串,你可以交换一个*和数字.在最前面添1.在一个地方插入*,问你使串满足入栈出栈的(RNP)运算法则. 思路: 引用:https://blog.csdn.net/u01158 ...
- 2018.10.26 浪在ACM 集训队第四次测试赛
2018.10.26 浪在ACM 集训队第四次测试赛 题目一览表 来源 考察知识点 完成时间 A 生活大爆炸版 石头剪刀布 NOIP 提高组 2014 模拟??? 2018.11.9 B 联合 ...
- 2018.10.2浪在ACM 集训队第三次测试赛
2018.10.26 浪在ACM 集训队第三次测试赛 今天是暴力场吗???????可怕 题目一览表 来源 考察知识点 完成时间 A 1275 珠心算测试 NOIP 普及组 2014 暴力??? 201 ...
- 2018.12.21 浪在ACM 集训队第十次测试赛
浪在ACM 集训队第十次测试赛 A Diverse Substring B Vasya and Books C Birthday D LCM A 传送门 题解 B 传送门 题解: 这道题,就比较简单 ...
- 2018.12.14 浪在ACM 集训队第九次测试赛
浪在ACM 集训队第九次测试赛 B Battleship E Masha and two friends B 传送门 题意: 战船上有占地n*n的房间cells[][],只由当cells[i][j]= ...
- 2018.10.2浪在ACM 集训队第二次测试赛
2018.10.26 浪在ACM 集训队第二次测试赛 题目一览表 来源 考察知识点 A 1273 海港 NOIP 普及组 2016 差分数组+二分 B 1274 魔法阵 C 1267 金币 ...
- 2018.12.7 浪在ACM 集训队第八次测试赛
2018.12.7 浪在ACM 集训队第八次测试赛 https://blog.csdn.net/QLU_minoz/article/details/84886717 感谢苗学林同学C题和D题题解 ...
- 2018.11.23 浪在ACM 集训队第六次测试赛
2018.11.23 浪在ACM 集训队第六次测试赛 整理人:刘文胜 div 2: A: Jam的计数法 参考博客:[1] 万众 B:数列 参考博客: [1] C:摆花 参考博客: [1] D:文化之 ...
随机推荐
- [Protractor] Testing With Protractor Page Objects
Protractor Page Objects are a recommended for testing your AngularJS applications. Page Objects abst ...
- PHP函数的默认参数
<?php /** * 函数的参数个数任意 */function foo() { $args = func_get_args(); static $i = 0; //统计参数个数 /* fore ...
- Java基础知识强化20:面向对象和面向过程的思想对比
面向对象与面向过程的区别 1. 与面向对象编程思想相比较的,往往是面向过程的编程思想,其实在我来理解,两者并不冲突,原因是面向对象的编程也必须使用面向过程的思维来实现具体的功能,所以我认为,两者的区 ...
- c#委托中另外一种用法
在c#委托中,经常可能遇到函数重载的情况,可是又需要在一个函数中调用这些函数,一般我都是根据多个函数重载个数,也写上这么多个函数重载.比如 public double T1(int r) { retu ...
- C#App.config的使用
为什么使用App.config, 在连接数据的时候将连接字符串写在了类中,如果更换数据库地址,则需要修改这个类,然后重新编译才可以重新连接数据库.在这个时候我们就可以将连接信息放到配置文件App.co ...
- react.js 你应知道的9件事
React.js 初学者应该知道的 9 件事 本文假定你已经有了一下基本的概念.如果你不熟悉 component.props 或者 state 这些名词,你最好先去阅读下官方起步和手册.下面的代码 ...
- 基于PHP和mysql的自动生成表单
开发背景:公司要求管理系统能够由管理员在前台页面管理系统表单,能够对表单进行增删改查基本操作,表单的各个字段都可以被修改.删除,可以添加新的字段,并且不影响系统正常运行,前台表单展示要由系统自动处理, ...
- Thinkphp 空操作、空控制器、命名空间
1.空操作 空操作是指系统在找不到请求的操作方法的时候,会定位到空操作(_empty)方法来执行,利用这个机制,我们可以实现错误页面和一些URL的优化. http://网址/index.php/Hom ...
- 【Linux】 任务调度/计划 cron
实时查看日志: tail -f /var/log/cron 显示任务调度 bash#crontab -u username -l 编辑 bash#crontab -u username -e 内容: ...
- CWnd类
CWnd类的成员 .数据成员 m_hWnd 指明与这个CWnd对象相关联的HWND句柄 .构造和析构 CWnd 构造一个CWnd对象 DestroyWindow 销毁相关联的Windows窗口 .初始 ...