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.pswp.cn/news/258050.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/258050.shtml
英文地址,請注明出處:http://en.pswp.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;能夠帶來哪些奇妙的事…