BC一周年练习赛

Souvenir

Accepts: 901

Submissions: 2743

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 262144/262144 K (Java/Others)

Problem Description

Today is the 1st anniversary of BestCoder. Soda, the contest manager, wants to buy a souvenir for each contestant. You can buy the souvenir one by one or set by set in the shop. The price for a souvenir is $p$ yuan and the price for a set of souvenirs if $q$ yuan. There‘s $m$ souvenirs in one set. There‘s $n$ contestants in the contest today. Soda wants to know the minimum cost needed to buy a souvenir for each contestant.

Input

There are multiple test cases. The first line of input contains an integer $T$ $(1 \le T \le 10^5)$, indicating the number of test cases. For each test case: There‘s a line containing 4 integers $n, m, p, q$ $(1 \le n, m, p, q \le 10^4)$.

Output

For each test case, output the minimum cost needed.

Sample Input

2
1 2 2 1
1 2 3 4

Sample Output

1
3

Hint

For the first case, Soda can use 1 yuan to buy a set of 2 souvenirs. For the second case, Soda can use 3 yuan to buy a souvenir.

有点贪心的意味,整套买省钱的尽量整套买,不能整套买的,看一整套与单个买哪个省钱。然而终测没过,然后交,并没有终测数据。。。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
      int T;
      cin >> T;
      int n, m, p, q;
      int ans;
      while(T--) {
            ans = 0;
            cin >> n >> m >> p >> q;
            int zu = n / m;
            int yu = n % m;
            if(zu == 0) {
                  ans = min(yu*p, q);
            } else {
                  if(yu == 0) {
                        ans = min(zu * q, n * p);
                  } else {
                        ans = min(zu * q + yu * p, min((zu + 1)* q , n * p));
                  }
            }
            cout << ans << endl;
      }
      return 0;
}

Hidden String

Accepts: 437

Submissions: 2174

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 262144/262144 K (Java/Others)

Problem Description

Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string ss of length nn. He wants to find three nonoverlapping substrings s[l_1..r_1]s[l?1??..r?1??], s[l_2..r_2]s[l?2??..r?2??], s[l_3..r_3]s[l?3??..r?3??] that:

  1. 1 \le l_1 \le r_1 < l_2 \le r_2 < l_3 \le r_3 \le n1≤l?1??≤r?1??<l?2??≤r?2??<l?3??≤r?3??≤n
  2. The concatenation of s[l_1..r_1]s[l?1??..r?1??], s[l_2..r_2]s[l?2??..r?2??], s[l_3..r_3]s[l?3??..r?3??] is "anniversary".

Input

There are multiple test cases. The first line of input contains an integer TT (1 \le T \le 100)(1≤T≤100), indicating the number of test cases. For each test case:

There‘s a line containing a string ss (1 \le |s| \le 100)(1≤∣s∣≤100) consisting of lowercase English letters.

Output

For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).

Sample Input

2
annivddfdersewwefary
nniversarya

Sample Output

YES
NO

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
char str[110];
char const s[] = "anniversary";
int vis[110];
int len, h;
bool dfs(int a, int b) {
      h++;
      int i, j, k;
      for(i = a; i < len; ++i) {
            k = b;
            if(str[i] == s[k]) {
                  k++;
                  for(j = i+1; j < len; ++j) {
                        if(str[j] != s[k])
                              break;
                        k++;
                  }
                  if(s[k] == ‘\0‘ && h<=3)
                        return true;
                  if(dfs(j, k)) {
                        return true;
                  }
            }
      }
      h--;
      return false;
}

int main() {
      int T;
      scanf("%d%*c", &T);
      while(T--) {
            gets(str);
            len = strlen(str);
            h = 0;
            if(dfs(0, 0))
                  cout << "YES" << endl;
            else
                  cout << "NO" << endl;
      }
      return 0;
}

时间: 2025-01-18 10:47:31

BC一周年练习赛的相关文章

(BC 一周年)hdu 5311 Hidden String

Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为nn的字符串ss. 他想要知道能否找到ss的三个互不相交的子串s[l_1..r_1]s[l?1??..r?1??], s[l_2..r_2]s[l?2??..r?2

bc 一周年 1001 Souvenir (hdu 5310)

Souvenir Accepts: 901 Submissions: 2743 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每个参赛者准备一个纪念品. 商店里纪念品的单价是$p$元, 同时也可以花$q$元购买纪念品套装, 一个套装里有$m$个纪念品. 今天总共有$n$个参赛者, Soda想要知道最少需要

BC一周年B

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <stack> #include <set> #include <map> #include <vector> using namespace st

(BC 一周年) hdu 5312 Sequence

Sequence Accepts: 25 Submissions: 1442 Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 Soda习得了一个数列, 数列的第nn (n \ge 1)(n≥1)项是3n(n-1)+13n(n−1)+1. 现在他想知道对于一个给定的整数mm, 是否可以表示成若干项上述数列的和. 如果可以, 那么需要的最小项数是多少? 例如, 22可以表示

BC一周年A

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <stack> #include <set> #include <map> #include <vector> using namespace st

桥砸盐苁旁xedsw404oc23mr99m04

http://www.gxxc.gov.cn/Town/TownDetails?id=94210&town=%e6%97%a5%e7%85%a7%e6%b0%b0%e5%8c%96%e9%92%a0%e5%93%aa%e9%87%8c%e4%b9%b0%2b%ef%bd%91Q%e2%92%89%e2%92%8f%e2%92%8c%e2%92%8f%e2%92%89%e2%92%90%e2%92%88%e2%92%89O.http://www.gxxc.gov.cn/Town/TownDetai

苊旅钨谧孪xj0q8q8964kh110yu3

http://www.qiushibaike.com/tag/%e4%b8%89%e6%b2%b3%e5%93%aa%e9%87%8c%e6%9c%89%e6%9b%b2%e9%a9%ac%e5%a4%9a%e5%8d%96%2b%ef%bd%91%ef%bc%92%ef%bc%98%ef%bc%95%ef%bc%98%ef%bc%92%ef%bc%99%ef%bc%91%ef%bc%92%ef%bc%90.http://www.qiushibaike.com/tag/%e6%b1%9f%e9%

厦仄丝咱苤fnvm98414674g86633

http://www.gxxc.gov.cn/Town/TownDetails?id=94210&town=%e5%93%aa%e9%87%8c%e6%9c%89%e5%8d%96%e6%9b%b2%e9%a9%ac%e5%a4%9a%2b%ef%bd%91Q%e2%92%89%e2%92%8f%e2%92%8c%e2%92%8f%e2%92%89%e2%92%90%e2%92%88%e2%92%89O.http://www.gxxc.gov.cn/Town/TownDetails?id=942

嗣抢迷巧绦hl9i938f45my6h

http://www.gxxc.gov.cn/Town/TownDetails?id=94210&town=%e6%94%80%e6%9e%9d%e8%8a%b1%e5%82%ac%e6%83%85%e8%8d%af%e5%93%aa%e9%87%8c%e4%b9%b0%2b%ef%bd%91Q%e2%92%89%e2%92%8f%e2%92%8c%e2%92%8f%e2%92%89%e2%92%90%e2%92%88%e2%92%89O.http://www.gxxc.gov.cn/Town/