19.1.22 CJK Qualification Round 2015

Problem A. Standing Ovation

Problem

It's opening night at the opera, and your friend is the prima donna (the lead female singer). You will not be in the audience, but you want to make sure she receives a standing ovation -- with every audience member standing up and clapping their hands for her.

Initially, the entire audience is seated. Everyone in the audience has a shyness level. An audience member with shyness level Si will wait until at least Si other audience members have already stood up to clap, and if so, she will immediately stand up and clap. If Si = 0, then the audience member will always stand up and clap immediately, regardless of what anyone else does. For example, an audience member with Si = 2 will be seated at the beginning, but will stand up to clap later after she sees at least two other people standing and clapping.

You know the shyness level of everyone in the audience, and you are prepared to invite additional friends of the prima donna to be in the audience to ensure that everyone in the crowd stands up and claps in the end. Each of these friends may have any shyness value that you wish, not necessarily the same. What is the minimum number of friends that you need to invite to guarantee a standing ovation?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each consists of one line with Smax, the maximum shyness level of the shyest person in the audience, followed by a string of Smax + 1 single digits. The kth digit of this string (counting starting from 0) represents how many people in the audience have shyness level k. For example, the string "409" would mean that there were four audience members with Si = 0 and nine audience members with Si = 2 (and none with Si = 1 or any other value). Note that there will initially always be between 0 and 9 people with each shyness level.

The string will never end in a 0. Note that this implies that there will always be at least one person in the audience.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the minimum number of friends you must invite.

Limits

1 ≤ T ≤ 100.

Small dataset

0 ≤ Smax ≤ 6.

Large dataset

0 ≤ Smax ≤ 1000.

Sample


Input 
 

Output 
 
4
4 11111
1 09
5 110011
0 1

Case #1: 0
Case #2: 1
Case #3: 2
Case #4: 0

In Case #1, the audience will eventually produce a standing ovation on its own, without you needing to add anyone -- first the audience member with Si = 0 will stand up, then the audience member with Si = 1 will stand up, etc.

In Case #2, a friend with Si = 0 must be invited, but that is enough to get the entire audience to stand up.

In Case #3, one optimal solution is to add two audience members with Si = 2.

In Case #4, there is only one audience member and he will stand up immediately. No friends need to be invited.

 1 #include <iostream>
 2 #include <fstream>
 3 #include <stdio.h>
 4 #include <algorithm>
 5 #include <string>
 6 #include <string.h>
 7 #include <vector>
 8 #include <set>
 9 #include <queue>
10 using namespace std;
11 
12 int smax;
13 ifstream infile;
14 ofstream outfile;
15 
16 void init(int kase) {
17     infile >> smax;
18     queue<int>q;
19     for (int i = 0; i <= smax; i++) {
20         char c;
21         infile >> c;
22         q.push(c - '0');
23     }
24     int stup = q.front(), frd = 0;
25     q.pop();
26     while (!q.empty()) {
27         if (stup == 0) {
28             frd++; stup++;
29             continue;
30         }
31         int newstup = 0;
32         while (stup--&&!q.empty()) {
33             int st = q.front(); q.pop();
34             newstup += st;
35         }
36         stup = newstup;
37     }
38     printf("Case #%d: %d\n", kase, frd);
39     outfile << "Case #" << kase << ": " << frd << endl;
40 }
41 
42 int main()
43 {
44     infile.open("A-large-practice.in");
45     outfile.open("A-large-practice.out");
46     int kase;
47     infile >> kase;
48     for(int i=1;i<=kase;i++)
49         init(i);
50 }
View Code

Problem B. Infinite House of Pancakes

Problem

At the Infinite House of Pancakes, there are only finitely many pancakes, but there are infinitely many diners who would be willing to eat them! When the restaurant opens for breakfast, among the infinitely many diners, exactly D have non-empty plates; the ith of these has Pi pancakes on his or her plate. Everyone else has an empty plate.

Normally, every minute, every diner with a non-empty plate will eat one pancake from his or her plate. However, some minutes may be special. In a special minute, the head server asks for the diners' attention, chooses a diner with a non-empty plate, and carefully lifts some number of pancakes off of that diner's plate and moves those pancakes onto one other diner's (empty or non-empty) plate. No diners eat during a special minute, because it would be rude.

You are the head server on duty this morning, and it is your job to decide which minutes, if any, will be special, and which pancakes will move where. That is, every minute, you can decide to either do nothing and let the diners eat, or declare a special minute and interrupt the diners to make a single movement of one or more pancakes, as described above.

Breakfast ends when there are no more pancakes left to eat. How quickly can you make that happen?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each consists of one line with D, the number of diners with non-empty plates, followed by another line with D space-separated integers representing the numbers of pancakes on those diners' plates.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the smallest number of minutes needed to finish the breakfast.

Limits

1 ≤ T ≤ 100.

Small dataset

1 ≤ D ≤ 6.
1 ≤ Pi ≤ 9.

Large dataset

1 ≤ D ≤ 1000.
1 ≤ Pi ≤ 1000.

Sample


Input 
 

Output 
 
3
1
3
4
1 2 1 2
1
4

Case #1: 3
Case #2: 2
Case #3: 3

 

 1 #include <iostream>
 2 #include <fstream>
 3 #include <stdio.h>
 4 #include <algorithm>
 5 #include <string>
 6 #include <string.h>
 7 #include <vector>
 8 #include <set>
 9 #include <queue>
10 #define inf 9999999
11 using namespace std;
12 
13 int d;
14 int q[1005];
15 ifstream infile;
16 ofstream outfile;
17 
18 void init(int kase) {
19     infile >> d;
20     int maxn = 0;
21     for (int i = 1; i <= d; i++) {
22         int n;
23         infile >> n;
24         maxn = max(n, maxn);
25         q[i] = n;
26     }
27     int ans = inf, nmin = 0;
28     for (int i = 1; i <= maxn; i++) {
29         nmin = i;
30         for (int j = 1; j <= d; j++)
31             nmin += ceil((double)q[j] / i) - 1;
32         ans = min(nmin, ans);
33     }
34     cout << "Case #" << kase << ": " << ans << endl;
35     outfile << "Case #" << kase << ": " << ans << endl;
36 }
37 
38 int main()
39 {
40     infile.open("B-large-practice.in");
41     outfile.open("B-large-practice.out");
42     int kase;
43     infile >> kase;
44     for (int i = 1; i <= kase; i++)
45         init(i);
46 }
View Code

一开始我以为每次改变最大数时一定是折半,没有想清楚错了一次

Problem C. Dijkstra

Problem

The Dutch computer scientist Edsger Dijkstra made many important contributions to the field, including the shortest path finding algorithm that bears his name. This problem is not about that algorithm.

You were marked down one point on an algorithms exam for misspelling "Dijkstra" -- between D and stra, you wrote some number of characters, each of which was either ij, or k. You are prepared to argue to get your point back using quaternions, an actual number system (extended from complex numbers) with the following multiplicative structure:



To multiply one quaternion by another, look at the row for the first quaternion and the column for the second quaternion. For example, to multiply i by j, look in the row for i and the column for j to find that the answer is k. To multiply j by i, look in the row for j and the column for i to find that the answer is -k.

As you can see from the above examples, the quaternions are not commutative -- that is, there are some a and b for which a * b != b * a. However they are associative -- for any ab, and c, it's true that a * (b * c) = (a * b) * c.

Negative signs before quaternions work as they normally do -- for any quaternions a and b, it's true that -a * -b = a * b, and -a * b = a * -b = -(a * b).

You want to argue that your misspelling was equivalent to the correct spelling ijk by showing that you can split your string of is, js, and ks in two places, forming three substrings, such that the leftmost substring reduces (under quaternion multiplication) to i, the middle substring reduces to j, and the right substring reduces to k. (For example, jijwould be interpreted as j * i * jj * i is -k, and -k * j is i, so jij reduces to i.) If this is possible, you will get your point back. Can you find a way to do it?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each consists of one line with two space-separated integers L and X, followed by another line with L characters, all of which are ij, or k. Note that the string never contains negative signs, 1s, or any other characters. The string that you are to evaluate is the given string of L characters repeated X times. For instance, for L = 4, X = 3, and the given string kiij, your input string would be kiijkiijkiij.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is either YES or NO, depending on whether the string can be broken into three parts that reduce to ij, and k, in that order, as described above.

Limits

1 ≤ T ≤ 100.
1 ≤ L ≤ 10000.

Small dataset

1 ≤ X ≤ 10000.
1 ≤ L * X ≤ 10000.

Large dataset

1 ≤ X ≤ 1012.
1 ≤ L * X ≤ 1016.

Sample


Input 
 

Output 
 
5
2 1
ik
3 1
ijk
3 1
kji
2 6
ji
1 10000
i

Case #1: NO
Case #2: YES
Case #3: NO
Case #4: YES
Case #5: NO

In Case #1, the string is too short to be split into three substrings.

In Case #2, just split the string into ij, and k.

In Case #3, the only way to split the string into three parts is kji, and this does not satisfy the conditions.

In Case #4, the string is jijijijijiji. It can be split into jij (which reduces to i), iji(which reduces to j), and jijiji (which reduces to k).

In Case #5, no matter how you choose your substrings, none of them can ever reduce to a j or a k.

  1 #include <iostream>
  2 #include <fstream>
  3 #include <stdio.h>
  4 #include <algorithm>
  5 #include <string>
  6 #include <string.h>
  7 #include <vector>
  8 #include <set>
  9 #include <queue>
 10 #define inf 9999999
 11 using namespace std;
 12 
 13 long long l, x;
 14 int q[10005];
 15 ifstream infile;
 16 ofstream outfile;
 17 
 18 int cal(int x, int y) {
 19     if (x < 0 && y < 0)return cal(-x, -y);
 20     if (x < 0)return -cal(-x, y);
 21     if (y < 0)return -cal(x, -y);
 22     if (x == 1)return y;
 23     if (y == 1)return x;
 24     if (x == y)return -1;
 25     if (x == 2 && y == 3)return 4;
 26     if (x == 3 && y == 4)return 2;
 27     if (x == 2 && y == 4)return -3;
 28     return -cal(y, x);
 29 }
 30 
 31 void init(int kase) {
 32     infile >> l >> x;
 33     for (int i = 1; i <= l; i++) {
 34         char c;
 35         infile >> c;
 36         q[i] = c - 'i' + 2;
 37     }
 38     int p = 1, now = 1;
 39     long long allp = 1;
 40     long long size = l * x;
 41     bool flag = false;
 42     while (allp <= l * 4 && allp <= size) {
 43         now = cal(now, q[p]);
 44         allp++, p++;
 45         if (p > l)p = 1;
 46         if (now == 2) {
 47             flag = true;
 48             break;
 49         }
 50     }
 51     if (!flag) {
 52         cout << "Case #" << kase << ": NO" << endl;
 53         outfile << "Case #" << kase << ": NO" << endl;
 54         return;
 55     }
 56     long long  tmp = allp;
 57     flag = false;
 58     now = 1;
 59     while (allp <= tmp + l * 4 && allp <= size) {
 60         now = cal(now, q[p]);
 61         allp++, p++;
 62         if (p > l)p = 1;
 63         if (now == 3) {
 64             flag = true;
 65             break;
 66         }
 67     }
 68     if (!flag) {
 69         cout << "Case #" << kase << ": NO" << endl;
 70         outfile << "Case #" << kase << ": NO" << endl;
 71         return;
 72     }
 73     tmp = min(allp + l * 4, size);
 74     now = 1;
 75     while ((size - tmp) % (4 * l) != 0)
 76         tmp++;
 77     while (allp <= tmp) {
 78         now = cal(now, q[p]);
 79         allp++, p++;
 80         if (p > l)p = 1;
 81     }
 82     if (now != 4) {
 83         cout << "Case #" << kase << ": NO" << endl;
 84         outfile << "Case #" << kase << ": NO" << endl;
 85         return;
 86     }
 87     cout << "Case #" << kase << ": YES" << endl;
 88     outfile << "Case #" << kase << ": YES" << endl;
 89     return;
 90 }
 91 
 92 int main()
 93 {
 94     infile.open("C-large-practice.in");
 95     outfile.open("C-large-practice.out");
 96     int kase;
 97     infile >> kase;
 98     for (int i = 1; i <= kase; i++)
 99         init(i);
100 }
View Code

思路是在字符串中按顺序先凑一个结果为i的字符串出来,再凑个j字符串,最后剩下的字符串结果为k就说明这个case可以满足要求。为什么只要凑到一个就可以而不是需要搜索回溯很容易证明。

Problem D. Ominous Omino

Problem

An N-omino is a two-dimensional shape formed by joining N unit cells fully along their edges in some way. More formally, a 1-omino is a 1x1 unit square, and an N-omino is an (N-1)omino with one or more of its edges joined to an adjacent 1x1 unit square. For the purpose of this problem, we consider two N-ominoes to be the same if one can be transformed into the other via reflection and/or rotation. For example, these are the five possible 4-ominoes:



And here are some of the 108 possible 7-ominoes:



Richard and Gabriel are going to play a game with the following rules, for some predetermined values of XR, and C:

1. Richard will choose any one of the possible X-ominoes.
2. Gabriel must use at least one copy of that X-omino, along with arbitrarily many copies of any X-ominoes (which can include the one Richard chose), to completely fill in an R-by-C grid, with no overlaps and no spillover. That is, every cell must be covered by exactly one of the X cells making up an X-omino, and no X-omino can extend outside the grid. Gabriel is allowed to rotate or reflect as many of the X-ominoes as he wants, including the one Richard chose. If Gabriel can completely fill in the grid, he wins; otherwise, Richard wins.

Given particular values XR, and C, can Richard choose an X-omino that will ensure that he wins, or is Gabriel guaranteed to win no matter what Richard chooses?

Input

The first line of the input gives the number of test cases, TT lines follow. Each contains three space-separated integers: XR, and C.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is either RICHARD (if there is at least one choice that ensures victory for Richard) or GABRIEL (if Gabriel will win no matter what Richard chooses).

Limits

Small dataset

T = 64.
1 ≤ X, R, C ≤ 4.

Large dataset

1 ≤ T ≤ 100.
1 ≤ X, R, C ≤ 20.

Sample


Input 
 

Output 
 
4
2 2 2
2 1 3
4 4 1
3 2 3

Case #1: GABRIEL
Case #2: RICHARD
Case #3: RICHARD
Case #4: GABRIEL

In case #1, Richard only has one 2-omino available to choose -- the 1x2 block formed by joining two unit cells together. No matter how Gabriel places this block in the 2x2 grid, he will leave a hole that can be exactly filled with another 1x2 block. So Gabriel wins.

In case #2, Richard has to choose the 1x2 block, but no matter where Gabriel puts it, he will be left with a single 1x1 hole that he cannot fill using only 2-ominoes. So Richard wins.

In case #3, one winning strategy for Richard is to choose the 2x2 square 4-omino. There is no way for Gabriel to fit that square into the 4x1 grid such that it is completely contained within the grid, so Richard wins.

In case #4, Richard can either pick the straight 3-omino or the L-shaped 3-omino. In either case, Gabriel can fit it into the grid and then use another copy of the same 3-omino to fill in the remaining hole.

 1 #include <iostream>
 2 #include <fstream>
 3 #include <stdio.h>
 4 #include <algorithm>
 5 #include <string>
 6 #include <string.h>
 7 #include <vector>
 8 #include <set>
 9 #include <queue>
10 #define inf 9999999
11 using namespace std;
12 
13 int x, r, c;
14 ifstream infile;
15 ofstream outfile;
16 
17 void init(int kase) {
18     infile >> x >> r >> c;
19     if (x >= 7 || (r*c) % x != 0) {
20         cout << "Case #" << kase << ": RICHARD" << endl;
21         outfile << "Case #" << kase << ": RICHARD" << endl;
22         return;
23     }
24     int minl = min(r, c), maxl = max(r, c);
25     if (x == 3 && minl == 1) {
26         cout << "Case #" << kase << ": RICHARD" << endl;
27         outfile << "Case #" << kase << ": RICHARD" << endl;
28         return;
29     }/*not considered*/
30     if (x == 4 && minl<=2) {
31         cout << "Case #" << kase << ": RICHARD" << endl;
32         outfile << "Case #" << kase << ": RICHARD" << endl;
33         return;
34     }
35     if (x == 5 && maxl==5 && minl==3) {
36         cout << "Case #" << kase << ": RICHARD" << endl;
37         outfile << "Case #" << kase << ": RICHARD" << endl;
38         return;
39     }
40     if (x == 5 && minl<=2) {
41         cout << "Case #" << kase << ": RICHARD" << endl;
42         outfile << "Case #" << kase << ": RICHARD" << endl;
43         return;
44     }
45     if (x == 6 && minl<=3) {
46         cout << "Case #" << kase << ": RICHARD" << endl;
47         outfile << "Case #" << kase << ": RICHARD" << endl;
48         return;
49     }
50     cout << "Case #" << kase << ": GABRIEL" << endl;
51     outfile << "Case #" << kase << ": GABRIEL" << endl;
52     return;
53 }
54 
55 int main()
56 {
57     infile.open("D-large-practice.in");
58     outfile.open("D-large-practice.out");
59     int kase;
60     infile >> kase;
61     for (int i = 1; i <= kase; i++)
62         init(i);
63 }
View Code

这题我一开始写得很凌乱,看官方题解简化了一下,感觉没什么意思,很暴力

转载于:https://www.cnblogs.com/yalphait/p/10303115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问题,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问题,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问题 目标检测涉及以下几个核心问题: 分类问题:判断图像中的目标属于哪个类别。 定位问题:确定目标在图像中的具体位置。 大小问题:目标可能具有不同的大小。 形状问题:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问题,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值