Facebook Hacker Cup 2018 Qualification Round

25: Tourist

暴力

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 string str[111];
 5 vector<string> v;
 6 map<string, int> mp;
 7 bool cmp(string a, string b) {
 8     return mp[a] < mp[b];
 9 }
10
11 int main() {
12     freopen("tourist.txt", "r", stdin);
13     freopen("tourist_out.txt", "w", stdout);
14     int T;
15     scanf("%d", &T);
16     for(int kase = 1; kase <= T; ++kase) {
17         LL K, N, V;
18         scanf("%lld %lld %lld", &N, &K, &V);
19         v.clear();
20         mp.clear();
21         for(int i = 0; i < N; ++i) cin >> str[i], mp[str[i]] = i;
22         int st = (K * (V - 1) - 1) % N;
23         printf("Case #%d:", kase);
24         for(int i = 1; i <= K; ++i) st = (st + 1) % N, v.push_back(str[st]);
25         sort(v.begin(), v.end(), cmp);
26         for(int i = 0; i < v.size(); ++i) printf(" %s", v[i].c_str());
27         puts("");
28     }
29     return 0;
30 }

Aguin

30: Interception

判奇偶

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 int main() {
 5     freopen("interception.txt", "r", stdin);
 6     freopen("interception_out.txt", "w", stdout);
 7     int T;
 8     scanf("%d", &T);
 9     for(int kase = 1; kase <= T; ++kase) {
10         int N, x;
11         scanf("%d", &N);
12         for(int i = N; i >= 0; --i) scanf("%d", &x);
13         if(N & 1) printf("Case #%d: 1\n0\n", kase);
14         else printf("Case #%d: 0\n", kase);
15     }
16     return 0;
17 }

Aguin

45: Ethan Searches for a String

找一个和前缀一样的

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 char A[2222];
 4
 5 int main() {
 6     freopen("ethan_searches_for_a_string.txt", "r", stdin);
 7     freopen("ethan_searches_for_a_string_out.txt", "w", stdout);
 8     int T;
 9     scanf("%d", &T);
10     for(int kase = 1; kase <= T; ++kase) {
11         scanf("%s", A + 1);
12         printf("Case #%d: ", kase);
13         int la = strlen(A + 1), flag = 0;
14         for(int i = 2; i <= la; ++i) {
15             if(A[i] != A[1]) continue;
16             int ok = 0;
17             for(int j = i; j <= la; ++j)
18                 if(A[j] != A[j-i+1]) {ok = 1; break;}
19             if(ok) {
20                 for(int j = 1; j < i; ++j) putchar(A[j]);
21                 puts(A + 1);
22                 flag = 1;
23                 break;
24             }
25         }
26         if(!flag) puts("Impossible");
27     }
28     return 0;
29 }

Aguin

原文地址:https://www.cnblogs.com/Aguin/p/9292902.html

时间: 2024-11-03 05:51:39

Facebook Hacker Cup 2018 Qualification Round的相关文章

DP VK Cup 2012 Qualification Round D. Palindrome pairs

题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 1 /* 2 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 3 DP:很巧妙的从i出发向两头扩展判断是否相同来找回文串 4 dpr[i] 代表记录从0到i间的回文子串的个数,dpl[i] 代表记录i之后的回文子串个数 5 两两相乘就行了 6 详细解释:http://blog.csdn.net/shiyuankongbu/article/details

Facebook Hacker Cup 2015 Round 1--Corporate Gifting(树形动态规划)

原题:https://www.facebook.com/hackercup/problems.php?pid=759650454070547&round=344496159068801 题意:给定一颗有根树,在树上下层的节点要给上层节点礼物,根节点的礼物则给慈善会,但是给礼物有个条件就是你不能送你的父节点已经送出的礼物.问满足要求的最少花费. 题解:这个题卡了一段时间,类似于染色问题,可以用树形动态规划求解.因为已知节点个数为N,则我们单个节点的最大花费不会超过log2(N) = 18. 1.

Facebook Hacker Cup 2015 Round 1--Winning at Sports(动态规划)

原题:https://www.facebook.com/hackercup/problems.php?pid=688426044611322&round=344496159068801 题意:你和一个朋友玩足球游戏,分数从0-0开始,最终你总是赢,并且你主要有两种方式赢,第一种stressFree方式你肯定要进第一个球并且总是比你的朋友分数高,第二种stressFull方式除了你的朋友达到最终分数时,在游戏中你不可能比你的朋友分数高.给出一个比分,请分别输出在两种情况下你能赢的方式. 题解:类似

Facebook Hacker Cup 2015 Round 1 Homework(附带测试数据)

题目描述: Homework10 points Your first-grade math teacher, Mr. Book, has just introduced you to an amazing new concept - primes! According to your notes, a prime is a positive integer greater than 1 that is divisible by only 1 and itself. Primes seem fun

Facebook Hacker Cup 2015 Round 1 Autocomplete (附带测试数据)

题目描述: Autocomplete25 points Since you crave state-of-the-art technology, you've just purchased a phone with a great new feature: autocomplete! Your phone's version of autocomplete has some pros and cons. On the one hand, it's very cautious. It only a

Facebook Hacker Cup 2015 Round 1 Winning at Sports (附带测试数据)

题目描述: Winning at Sports25 points In the game of Sports, the object is have more points than the other team after a certain amount of time has elapsed. Scores are denoted by two hyphen-separated integers. For example, scores may include 3-2, 4-1, or 1

Facebook Hacker Cup 2015 Round 1--Autocomplete(字典树新建与查询)

题意:给定N个字符串,让你依次先输入到手机的字典中,再打印出来,打印的时候我们只需要输出字符串的前缀或者全部字符串,要求此前缀不是以往任何字符串的前缀. 题解:典型的字典树,可以利用结构体数组方便的新建与查询,速度比链表更快.只需在插入字符串时统计最长相同的前缀即可. 代码如下: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define maxN 1000005

Facebook Hacker Cup 2015 Round 1--Homework(筛选法求素数)

题意:给定A,B,K(A<=B)三个数,问在[A,B]范围内的数素数因子个数为K的个数. 题解:典型的筛选法求素数.首先建立一个保存素数因子个数的数组factorNum[],以及到n为止含有素数因子个数为k的二维数组sumNum[n][k]. factorNum可以由筛选法确定,初始化数组为0. 1. 从小到大遍历给定最大范围内的数,若遍历到数n时,factorNum[n]=0则说明这个数是素数(前面没有它的因子). 2. 然后通过增加n的倍数,来筛选出最大范围内含有素数因子n的数. sumNu

Facebook Hacker Cup 2015 Round 1 --- Homework

给一个区间,求该区间内 质因子个数等于k的数 的个数. 暴力预处理一下啦 #include<cstdio> #include<cstring> using namespace std; const int maxn=10000010; bool pri[maxn]; int cnt[maxn]; void init() { memset(pri,1,sizeof pri); memset(cnt,0,sizeof cnt); for(int i=2;i<=10000000;i