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))。可以查阅相关资料自行选择学习。这里给出中心法。

 

 1 /****************************************/
 2 /*****            Desgard_Duan        *****/
 3 /****************************************/
 4 //#pragma comment(linker, "/STACK:102400000,102400000")
 5 #define _CRT_SECURE_NO_WARNINGS
 6 #include <iostream>
 7 #include <cstdio>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <string>
11 #include <algorithm>
12 #include <stack>
13 #include <map>
14 #include <queue>
15 #include <vector>
16 #include <set>
17 #include <functional>
18 #include <cmath>
19 #include <numeric>
20 
21 using namespace std;
22 
23 char s[500]; int len;
24 
25 inline void get_val(int &a) {
26     int value = 0, s = 1;
27     char c;
28     while ((c = getchar()) == ' ' || c == '\n');
29     if (c == '-') s = -s; else value = c - 48;
30     while ((c = getchar()) >= '0' && c <= '9')
31         value = value * 10 + c - 48;
32     a = s * value;
33 }
34 
35 int tofind(int h, int t) {
36     int re = t - h + 1;
37     while (h < t) {
38         if (s[h++] != s[t--]) return 0;
39     }
40     return re;
41 }
42 
43 int main() {
44     //freopen("huiwen.in", "r", stdin);
45     //freopen("huiwen.out","w",stdout);
46     int T;
47     cin >> T;
48     while (T--) {
49         scanf("%s", s);
50         len = strlen(s);
51         int ans = 1;
52         for (int i = 0; i < len - 1; i++)
53             for (int j = i + 1; j < len; j++) {
54                 ans = max(ans, tofind(i, j));
55             }
56         cout << ans << endl;
57     }
58     return 0;
59 }

 

 

2147 Problem B:

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

 1 /****************************************/
 2 /*****            Desgard_Duan        *****/
 3 /****************************************/
 4 //#pragma comment(linker, "/STACK:102400000,102400000")
 5 #define _CRT_SECURE_NO_WARNINGS
 6 #include <iostream>
 7 #include <cstdio>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <string>
11 #include <algorithm>
12 #include <stack>
13 #include <map>
14 #include <queue>
15 #include <vector>
16 #include <set>
17 #include <functional>
18 #include <cmath>
19 #include <numeric>
20 
21 using namespace std;
22 
23 inline void get_val(int &a) {
24     int value = 0, s = 1;
25     char c;
26     while ((c = getchar()) == ' ' || c == '\n');
27     if (c == '-') s = -s;
28     else value = c - 48;
29     while ((c = getchar()) >= '0' && c <= '9')
30         value = value * 10 + c - 48;
31     a = s * value;
32 }
33 
34 string str1, str2;
35 int main () {
36     int T;
37     //cin >> T;
38     while (cin >> str1 >> str2) {
39 
40         int ans = 0;
41         for (int i = 0 ; i < str1.size(); ++ i) {
42             if (str1[i] == str2[i]) {
43                 ans ++;
44             }
45         }
46         cout << ans << endl;
47     }
48     return 0;
49 }

 

2148 Problem C:

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

 1 /****************************************/
 2 /*****            Desgard_Duan        *****/
 3 /****************************************/
 4 //#pragma comment(linker, "/STACK:102400000,102400000")
 5 #define _CRT_SECURE_NO_WARNINGS
 6 #include <iostream>
 7 #include <cstdio>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <string>
11 #include <algorithm>
12 #include <stack>
13 #include <map>
14 #include <queue>
15 #include <vector>
16 #include <set>
17 #include <functional>
18 #include <cmath>
19 #include <numeric>
20 
21 using namespace std;
22 
23 inline void get_val(int &a) {
24     int value = 0, s = 1;
25     char c;
26     while ((c = getchar()) == ' ' || c == '\n');
27     if (c == '-') s = -s;
28     else value = c - 48;
29     while ((c = getchar()) >= '0' && c <= '9')
30         value = value * 10 + c - 48;
31     a = s * value;
32 }
33 
34 vector<pair<int, int> > shoes;
35 bool flag[1005];
36 
37 int main () {
38     int n, x, y;
39     //freopen("out.txt", "w", stdout);
40     while (~scanf ("%d", &n)) {
41         shoes.clear();
42         for (int i = 0; i < n; ++ i) {
43             cin >> x >> y;
44             shoes.push_back (make_pair(x, y));
45         }
46         sort (shoes.begin(), shoes.end());
47 
48         memset (flag, 0, sizeof (flag));
49         for (int i = 0; i < n; ++ i) {
50             if (flag[i]) {
51                 continue;
52             }
53             for (int j = 0; j < n; ++ j) {
54                 if (i == j) continue;
55                 else {
56                     if (shoes[i].first <= shoes[j].first && shoes[i].second >= shoes[j].second) {
57                         flag[i] = 1;
58                     }
59                 }
60             }
61         }
62         int cur = 0, ans = 1;
63         for (; cur < shoes.size() && flag[cur]; cur ++);
64         int last_end = shoes[cur].second, this_begin;
65         for (int i = cur + 1; i < shoes.size(); ++ i) {
66             if (flag[i]) continue;
67             this_begin = shoes[i].first;
68             if (last_end <= this_begin) {
69                 ans ++;
70                 last_end = shoes[i].second;
71             }
72         }
73         cout << ans << endl;
74 
75     }
76     return 0;
77 }

 

2149 Problem D:

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

 

 1 import java.math.*;
 2 import java.io.*;
 3 import java.util.*;
 4 
 5 public class Main {
 6     public static void main(String args[]) {
 7         Scanner in = new Scanner(System.in);
 8         while (in.hasNext()) {
 9             int n = in.nextInt();
10             BigInteger ans = BigInteger.ZERO;
11             for (int i = 0; i < n; ++i) {
12                 BigInteger a = in.nextBigInteger();
13                 if (i == 0) {
14                     ans = a;
15                 } else {
16                     ans = ans.min(a);
17                 }
18             }
19             System.out.println (ans);
20         }
21     }
22 }

 

 

2150 Problem E:

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

 1 /****************************************/
 2 /*****            Desgard_Duan        *****/
 3 /****************************************/
 4 //#pragma comment(linker, "/STACK:102400000,102400000")
 5 #define _CRT_SECURE_NO_WARNINGS
 6 #include <iostream>
 7 #include <cstdio>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <string>
11 #include <algorithm>
12 #include <stack>
13 #include <map>
14 #include <queue>
15 #include <vector>
16 #include <set>
17 #include <functional>
18 #include <cmath>
19 #include <numeric>
20 
21 using namespace std;
22 
23 inline void get_val(int &a) {
24     int value = 0, s = 1;
25     char c;
26     while ((c = getchar()) == ' ' || c == '\n');
27     if (c == '-') s = -s;
28     else value = c - 48;
29     while ((c = getchar()) >= '0' && c <= '9')
30         value = value * 10 + c - 48;
31     a = s * value;
32 }
33 
34 
35 int a, b, n;
36 set<int> S;
37 int main () {
38     while (cin >> a >> b >> n) {
39         S.clear();
40         if (n >= 6) {
41             S.insert (a);
42             S.insert (b);
43             S.insert (b - a);
44             S.insert (-a);
45             S.insert (-b);
46             S.insert (a - b);
47             cout << S.size() << endl;
48             continue;
49         } else {
50             int last = a, now = b, t;
51             S.insert (a);
52             S.insert (b);
53             for (int i = 3; i <= n; ++ i) {
54                 S.insert (now - last);
55                 t = now;
56                 now = now - last;
57                 last = t;
58             }
59             cout << S.size() << endl;
60         }
61     }
62     return 0;
63 }

 

 


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

——Desgard_Duan

2014.10.31

转载于:https://www.cnblogs.com/Destiny-Gem/p/4065932.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/258050.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

利用Vagrant and VirtualBox搭建core os环境

利用Vagrant and VirtualBox搭建core os环境 系统环境 ubuntu 14.04 x64vagrant 1.7.4virtualbox 4.3.10git 1.9.1# 安装 virtualbox, git sudo apt-get install virtualbox, git# 软件中心的vagrant版本太低,因此去官网获取最新的软件包地址 wget https://releases.hashicorp.…

php关注 取消关注事件,微信公众平台开发关注/取消关注事件例子

用户在关注与取消关注公众号时&#xff0c;微信会把这个事件推送到开发者填写的URL。方便开发者给用户下发欢迎消息或者做帐号的解绑下面是一个微信公众平台关注和取消关注的实例:responseMsg();} else {$wechatObj->valid();}class wechatCallbackapiTest {public function…

DFS应用——遍历有向图+判断有向图是否有圈

【0】README 0.1&#xff09; 本文总结于 数据结构与算法分析&#xff0c; 源代码均为原创&#xff0c; 旨在 理解 “DFS应用——遍历有向图判断有向图是否有圈” 的idea 并用源代码加以实现 &#xff1b;0.2&#xff09; 判断有向图是否有圈的rule—— 一个有向图是无圈图当且…

AbleCloud智能行业解决方案助力体重秤企业向“中国智造”转变

近年来&#xff0c;体重秤消费群体的年龄层次与需求逐渐向多元化发展&#xff0c;品牌众多、竞争激烈的传统体重秤行业迎来了前所未有的挑战——智能体重秤成为行业发展的大趋势&#xff0c;功能单一、同质化严重已经成为阻碍传统体重秤企业成长的桎梏&#xff0c;打造出具备“…

javaScript事件(一)事件流

一、事件 事件是文档或者浏览器窗口中发生的&#xff0c;特定的交互瞬间。 事件是用户或浏览器自身执行的某种动作&#xff0c;如click,load和mouseover都是事件的名字。 事件是javaScript和DOM之间交互的桥梁。 你若触发&#xff0c;我便执行——事件发生&#xff0c;调用它的…

php输入对话框,如何使用JavaScript实现输入对话框

我们有时在网页上进行注册用户信息时会出现弹窗进行提示&#xff0c;你需要输入内容进行确认&#xff0c;那么&#xff0c;这样的输入对话框是怎么实现的呢&#xff1f;本篇文章就来介绍关于使用JavaScript实现输入对话框的方法。我们可以使用prompt显示输入对话框要在JavaScri…

软件缺陷的种类划分

按照软件缺陷的产生原因&#xff0c;可以将其划分为不同的缺陷类别&#xff1a; 1、功能不正常 简单地说就是所应提供的功能&#xff0c;在使用上并不符合产品设计规格说明书中规定的要求&#xff0c;或是根本无法使用。这个错误常常会发生在测试过程的初期和中期&#xff0c;有…

python——no module named XX

加PYTHONPATH吧&#xff0c;新建一个系统环境变量&#xff0c;把你的目录复制进去即可转载于:https://www.cnblogs.com/MarsMercury/p/4992629.html

CodeVS 1081 线段树练习 2

1081 线段树练习 2 时间限制: 1 s空间限制: 128000 KB题目等级 : 大师 Master题目描述 Description给你N个数&#xff0c;有两种操作 1&#xff1a;给区间[a,b]的所有数都增加X 2&#xff1a;询问第i个数是什么&#xff1f; 输入描述 Input Description第一行一个正整数n&#…

bzoj4144 [AMPPZ2014]Petrol 图论 最短路 并查集

bzoj4144 [AMPPZ2014]Petrol 图论 最短路 并查集 1、这道题我们主要就是要求出距离一个油站的最近的油站 首先我们dijkstra 求出任意一个点到 离他最近的油站的距离 2、然后会发现 如果一条边的两个端点 的最近油站不同的话 那么这条边就会在这两个油站的最短路上 3、然后对于…

python函数理解,python对函数的理解

函数函数可以提高编写代码效率、代码的重用、让程序更小、模块化可以将一段独立功能的代码集成在一个块中、封装独立功能# 函数定义(参数名为形式参数)def 函数名(参数名):函数体# 调用函数(享受封装的成功)函数名(实际参数)例&#xff1a;print函数print(sep,end) sep(元素中分…

06:空格分隔输出

描述 读入一个字符&#xff0c;一个整数&#xff0c;一个单精度浮点数&#xff0c;一个双精度浮点数&#xff0c;然后按顺序输出它们&#xff0c;并且要求在他们之间用一个空格分隔。输出浮点数时保留6位小数。 输入共有四行&#xff1a;第一行是一个字符&#xff1b;第二行是一…

iOS开发UI篇—九宫格坐标计算

iOS开发UI篇—九宫格坐标计算 一、要求 完成下面的布局 二、分析 寻找左边的规律&#xff0c;每一个uiview的x坐标和y坐标。 三、实现思路 (1)明确每一块用得是什么view (2)明确每个view之间的父子关系&#xff0c;每个视图都只有一个父视图&#xff0c;拥有很多的子视图。 (3)…

工业4.0时代企业如何用CRM实现模式变革

当前&#xff0c;全球经济正处于变革的巨大浪潮之中&#xff0c;对于制造业来说&#xff0c;德国提出工业4.0&#xff0c;美国提出工业互联网&#xff0c;而我国&#xff0c;正在大力推进“中国制造2025”。制造业实现转型升级势在必行。我国政府提出&#xff0c;要大力支持传统…

oracle 9.2.0.2,在RedHat enterprise server 3 安装oracle9i 2.0.0.1 并升级到9.2.0.6

oracle9i 2.0.4上个月从oracle网站下载没有安装在els3上。参考了网上的一些文章&#xff0c;并根据文章的提示找了一些资料和补丁&#xff0c;完成了这次的安装。[more]1.安装RedHat EL3现在的安装界面都做的很好了,一路NEXT就可以安装了.如果有困难,请参考其他linux安装文档进…

spring -mvc 将对象封装json返回时删除掉对象中的属性注解方式

spring -mvc 将对象封装json返回时删除掉对象中的属性注解方式 在类名,接口头上注解使用在 JsonIgnoreProperties(value{"comid"}) //希望动态过滤掉的属性 例 JsonIgnoreProperties(value{"comid"}) public interface 接口名称{ } JsonIgnorePro…

HawkHost老鹰主机更换主域名方法

http://www.yd631.com/change-hawkhost-primary-domain/圣诞节优惠期间&#xff0c;很多童鞋们购买了老鹰主机&#xff0c;可能由于大家初次使用海外主机或者是CP面板的空间。购买主机的时候主域名是随便输入的或者是输入后想换一个。我们可以通过以下方法进行操作。之前我们QQ…

ERP CRM与SCM整合过程中的知识转移

ERP(Enterprise Resource Planning&#xff0c;企业资源计划)、CRM(Customer Relationship Management&#xff0c;客户关系管理)、SCM、CRM(Customer Relationship Management&#xff0c;客户关系管理)、SCM(supply chain management&#xff0c;供应链管理)作为现代企业管理…

ubuntu 64 12.04 oracle,ubuntu server 12.04 x86_64 下安装oracle xe 11 x86_64

1.下载oracle xe我下载的是oracle-xe-11.2.0-1.0.x86_64.rpm.zip2. 安装必要程序或文件$sudo apt-get install unzip chkconfig libaio1 alien3.解压上面的oraclexxx.zip文件,然后进行转换$sudo alien -d --scripts oracle-xe-11.2.0-1.0.x86_64.rpm上面转换完成后会生成一个 o…

IEnumerable 遍历用法

咋一看到IEnumerable这个接口&#xff0c;我们可能会觉得很神奇&#xff0c;在一般的编程时&#xff0c;基本上我们是想不到去用它的&#xff0c;可是&#xff0c;俗话说得好&#xff0c;存在便是道理&#xff0c;那么&#xff0c;它对我们来说&#xff0c;能够带来哪些奇妙的事…