2017-12-06 ACM校级竞赛心得

3 篇文章 0 订阅
1 篇文章 0 订阅

2017-12-06 ACM校级竞赛心得

上了这么久的竞赛培训,终于实战了一下,竞赛现场十分火爆,大牛们的比分十分接近,我和布道者加上一名帅气的翻译作为一组算是观战了。

下面就是亮题了

1000整除的尾数

Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 53 Accepted Submission(s) : 9

Problem Description

一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢?

Input

输入数据有若干组,每组数据包含二个整数a,b(0<a<10000,10<b<100),若遇到0 0则处理结束。

Output

对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。

Sample Input

200 40
1992 95
0 0

Sample Output

00 40 80
15

Source

2007省赛集训队练习赛(2)

解题思路

毕竟是签到题,还是比较容易的,唯一的坑就是输出格式,布道者成功掉进去了。代码如下

#include <iostrem>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
    int a,b,x,i=0,j=0,t,o=0;
    int c[100];
    while(scanf("%d %d",&a,&b)&&(!(!a&&!b)))
    {       
        for(i=0;i<100;i++)
        {           
            x=a*100+i;          
            if(x%b==0)
            {               
                c[o]=i;
                o++;
            }
        }
        t=o;
        o=0;
        while(o<t-1)
        {
            if(c[o]<10)
            {
                cout<<0<<c[o]<<' ';
            }
            else
            {
                cout<<c[o]<<' ';
            }   
            o++;
        }
        cout<<c[o]<<endl;
        o=0;            
    }
    return 0;
}

一直到最后都没有检查出来,我修正后代码如下

#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
    int num1,num2,i,a,j=0,out[10001]={0};
    while(cin>>num1>>num2&&(!(!num1&&!num2)))
    {
        for(i=0;i<100;i++)
        {
            a=num1*100+i;
            if(a%num2==0)
            {
                out[j++]=i;
            }
        }
        for(i=0;i<j-1;i++)
        {
            printf("%02d ",out[i]);             
        }
        printf("%02d",out[i]);
        cout<<endl;
        j=0;
    }
    return 0;
}

问题就是出在如果输出值小于10时要在前面补0,下次要吸取经验。下面看第二题.

1001 A Simple Question of Chemistry

Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 35 Accepted Submission(s) : 12

Problem Description

Your chemistry lab instructor is a very enthusiastic graduate student who clearly has forgotten what their undergraduate Chemistry 101 lab experience was like. Your instructor has come up with the brilliant idea that you will monitor the temperature of your mixture every minute for the entire lab. You will then plot the rate of change for the entire duration of the lab. Being a promising computer scientist, you know you can automate part of this procedure, so you are writing a program you can run on your laptop during chemistry labs. (Laptops are only occasionally dissolved by the chemicals used in such labs.) You will write a program that will let you enter in each temperature as you observe it. The program will then calculate the difference between this temperature and the previous one, and print out the difference. Then you can feed this input into a simple graphing program and finish your plot before you leave the chemistry lab.

Input

The input is a series of temperatures, one per line, ranging from -10 to 200. The temperatures may be specified up to two decimal places. After the final observation, the number 999 will indicate the end of the input data stream. All data sets will have at least two temperature observations.

Output

Your program should output a series of differences between each temperature and the previous temperature. There is one fewer difference observed than the number of temperature observations (output nothing for the first temperature). Differences are always output to two decimal points, with no leading zeroes (except for the ones place for a number less than 1, such as 0.01) or spaces.
After the final output, print a line with “End of Output”

Sample Input

10.0
12.05
30.25
20
999

Sample Output

2.05
18.20
-10.25
End of Output

Source

Mid-Atlantic USA 2003

解题思路

这道签到题是我解得,简单所以就直接放A掉的代码。

#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;

int main(int argc, char *argv[])
{
    double num,in[10000]={0},out[10000]={0};
    int i=0,j,gs;
    while(cin>>num&&num!=999)
    {
        in[i++]=num;
    }
    gs=i;
    for(j=0;j<gs-1;j++)
    {
        printf("%.2lf\n",in[j+1]-in[j]);
    }
    cout<<"End of Output"<<endl;
    return 0;
}

下一题

1002 Triangular Sums


Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 37 Accepted Submission(s) : 12

Problem Description

The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number of points in a triangular array with n points on side.
For example T(4):
        X
      X  X
    X  X  X
  X  X  X  X

Write a program to compute the weighted sum of triangular numbers:

W(n) = SUM[k = 1..n; k*T(k+1)]

Input

The first line of input contains a single integer N, (1 <= N <= 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integer n, (1 <= n <= 300), which is the number of points on a side of the triangle.

Output

For each dataset, output on a single line the dataset number, (1 through N), a blank, the value of n for the dataset, a blank, and the weighted sum , W(n), of triangular numbers for n.

Sample Input

4
3
4
5
10

Sample Output

1 3 45
2 4 105
3 5 210
4 10 2145

Source

Greater New York Regional 2006

解题思路

这题是布道者解的题,他又成功陷入陷阱,数组定义过小,我就直接放A掉的代码

#include <stdio.h>
int SUM(long long n){
    long long sum=0,i=1,j=3;
    while(i<=n){
        sum+=i*j;
        i++;
        j+=i+1;
    }
    return sum;
}
int main()
{
    int n,i=0;
    long long a[1002][2]={0};
    scanf("%d",&n);
    while(i<n){
        scanf("%lld",&a[i][1]);
        a[i][2]=SUM(a[i][1]);
        i++;
    }
    i=0;
    while(i<n){
        printf("%d %lld %lld\n",i+1,a[i][1],a[i][2]);
        i++;
    }
    return 0;
}

下一题

1003 Crusaders Quest


Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 2 Accepted Submission(s) : 0

Problem Description

Crusaders Quest is an interesting mobile game. A mysterious witch has brought great darkness to the game world, and the only hope for your kingdom is to save the Goddesses so that they can unleash their power to fight against the witch.
这里写图片描述

In order to save the game world, you need to choose three heroes to fight for victory and use their skills wisely. Nine skill blocks of three different types (three blocks per type) will be presented at the bottom of the screen. If (k) ((k \ge 1)) consecutive blocks are of the same type, you can tap on them and eliminate them, thus triggering the powerful skill they represent. After the elimination, the blocks to their left will be connected with the blocks to their right. Moreover, if (k=3) consecutive blocks of the same type are eliminated, the powerful skill they unleash will be upgraded to a super skill, which is the most powerful skill of all.
DreamGrid is a newbie in this game, and he wants to trigger the super skill as many times as he can. Given nine skill blocks satisfying the description above, please help DreamGrid calculate the maximum number of times he can trigger the super skill.

Input

There are multiple test cases. The first line of input contains an integer (T) (about 50), indicating the number of test cases. For each test case:

The first line contains a string (s) ((|s| = 9)) consisting of three ‘g’s, three ‘a’s and three ‘o’s, representing the nine skill blocks of three different types. Each type of character represents one type of skill block.

Output

For each test case, output an integer denoting the maximum number of times DreamGrid can trigger the super skill.

Sample Input

7
gggaaaooo
aaoogggoa
googgaaao
agogaooag
goooggaaa
gogogoaaa
gaogaogao

Sample Output

3
3
2
1
3
2
1

Hint

For the first sample test case, DreamGrid can first eliminate “aaa” (one super skill triggered), thus changing the skill blocks to “gggooo”. He can then eliminate “ggg” (another super skill triggered) and finally eliminate “ooo” (a third super skill triggered). So the answer is 3.

For the second sample test case, DreamGrid can first eliminate “ggg” (one super skill triggered), thus changing the skill blocks to “aaoooa”. He can then eliminate “ooo” (another super skill triggered) and finally eliminate “aaa” (a third super skill triggered). So the answer is also 3.

For the third sample test case, DreamGrid can first eliminate “aaa” (one super skill triggered), thus changing the skill blocks to “googgo”. He can then eliminate “oo” to obtain “gggo”, and eliminate “ggg” (another super skill triggered) to obtain “o”. So the answer is 2. It is easy to prove that he cannot trigger the super skill three times under this arrangement of skill blocks.

Source

The 2017 China Collegiate Programming Contest, Qinhuangdao Site

1004 String of CCPC


Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 0

Problem Description

BaoBao has just found a string (s) of length (n) consisting of ‘C’ and ‘P’ in his pocket. As a big fan of the China Collegiate Programming Contest, BaoBao thinks a substring (s_is_{i+1}s_{i+2}s_{i+3}) of (s) is “good”, if and only if (s_i = s_{i+1} = s_{i+3} =) ‘C’, and (s_{i+2} =) ‘P’, where (s_i) denotes the (i)-th character in string (s). The value of (s) is the number of different “good” substrings in (s). Two “good” substrings (s_is_{i+1}s_{i+2}s_{i+3}) and (s_js_{j+1}s_{j+2}s_{j+3}) are different, if and only if (i \ne j).
To make this string more valuable, BaoBao decides to buy some characters from a character store. Each time he can buy one ‘C’ or one ‘P’ from the store, and insert the character into any position in (s). But everything comes with a cost. If it’s the (i)-th time for BaoBao to buy a character, he will have to spend (i-1) units of value.

The final value BaoBao obtains is the final value of (s) minus the total cost of all the characters bought from the store. Please help BaoBao maximize the final value.

Input

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

The first line contains an integer \(n\) (\(1 \le n \le 2\times 10^5\)), indicating the length of string \(s\).

The second line contains the string \(s\) (\(|s| = n\)) consisting of ‘C’ and ‘P’.

It’s guaranteed that the sum of\(n\) over all test cases will not exceed \(10^6\).

Output

For each test case output one line containing one integer, indicating the maximum final value BaoBao can obtain.For each test case output one line containing one integer, indicating the maximum final value BaoBao can obtain.

Sample Input

3
3
CCC
5
CCCCP
4
CPCP

Sample Output

1
1
1

Hint

For the first sample test case, BaoBao can buy one ‘P’ (cost 0 value) and change (s) to “CCPC”. So the final value is 1 - 0 = 1.

For the second sample test case, BaoBao can buy one ‘C’ and one ‘P’ (cost 0 + 1 = 1 value) and change (s) to “CCPCCPC”. So the final value is 2 - 1 = 1.

For the third sample test case, BaoBao can buy one ‘C’ (cost 0 value) and change (s) to “CCPCP”. So the final value is 1 - 0 = 1.

It’s easy to prove that no strategies of buying and inserting characters can achieve a better result for the sample test cases.

Source

Mid-Atlantic USA 2003

1005 String Matching


Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 44 Accepted Submission(s) : 7

Problem Description

It’s easy to tell if two words are identical - just check the letters. But how do you tell if two words are almost identical? And how close is “almost”?

There are lots of techniques for approximate word matching. One is to determine the best substring match, which is the number of common letters when the words are compared letter-byletter.

The key to this approach is that the words can overlap in any way. For example, consider the words CAPILLARY and MARSUPIAL. One way to compare them is to overlay them:
CAPILLARY
MARSUPIAL
There is only one common letter (A). Better is the following overlay:
CAPILLARY
  MARSUPIAL

with two common letters (A and R), but the best is:
  CAPILLARY
MARSUPIAL

Which has three common letters (P, I and L).

The approximation measure appx(word1, word2) for two words is given by:
common letters * 2
-----------------------------

length(word1) + length(word2)

Thus, for this example, appx(CAPILLARY, MARSUPIAL) = 6 / (9 + 9) = 1/3. Obviously, for any word W appx(W, W) = 1, which is a nice property, while words with no common letters have an appx value of 0.

Input

The input for your program will be a series of words, two per line, until the end-of-file flag of -1.

Using the above technique, you are to calculate appx() for the pair of words on the line and print the result. For example:

CAR CART
TURKEY CHICKEN
MONEY POVERTY
ROUGH PESKY
A A
-1

The words will all be uppercase.

Output

Print the value for appx() for each pair as a reduced fraction, like this:

appx(CAR,CART) = 6/7
appx(TURKEY,CHICKEN) = 4/13
appx(MONEY,POVERTY) = 1/3
appx(ROUGH,PESKY) = 0
appx(A,A) = 1

Fractions reducing to zero or one should have no denominator.

Source

Pacific Northwest 1999

1006 One-Dimensional Maze


Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 11 Accepted Submission(s) : 5
Problem Description

BaoBao is trapped in a one-dimensional maze consisting of \(n\) grids arranged in a row! The grids are numbered from 1 to \(n\) from left to right, and the \(i\)-th grid is marked with a character \(s_i\), where \(s_i\)is either ‘L’ or ‘R’.
Starting from the \(m\)-th grid, BaoBao will repeatedly take the following steps until he escapes the maze:

If BaoBao is in the 1st grid or the\(n\)-th grid, then BaoBao is considered to arrive at the exit and thus can escape successfully.
Otherwise, let BaoBao be in the \(t\)-th grid. If \(s_t = \text{'L'}\), BaoBao will move to the \((t-1)\)-th grid; If \(s_t = \text{'R'}\), Baobao will move to the\((t+1)\)-th grid.
Before taking the above steps, BaoBao can change the characters in some grids to help himself escape. Concretely speaking, for the\(i\)-th grid, BaoBao can change\(s_i\) from ‘L’ to ‘R’, or from ‘R’ to ‘L’.

But changing characters in grids is a tiring job. Your task is to help BaoBao calculate the minimum number of grids he has to change to escape the maze.

Input

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

The first line contains two integers\(n\) and \(m\) (\(3 \le n \le 10^5\), \(1 < m < n\)), indicating the number of grids in the maze, and the index of the starting grid.

The second line contains a string \(s\) (\(|s| = n\))consisting of characters ‘L’ and ‘R’. The\(i\)-th character of\(s\) indicates the character in the\(i\)-th grid.

It is guaranteed that the sum of \(n\) over all test cases will not exceed\(10^6\).

Output

For each test case output one line containing one integer, indicating the minimum number of grids BaoBao has to change to escape the maze.

Source

The 2017 China Collegiate Programming Contest, Qinhuangdao Site

Sample Input

3
3 2
LRL
10 4
RRRRRRRLLR
7 4
RLLRLLR

Sample Output

0
2
1

Hint

For the first sample test case, BaoBao doesn’t have to change any character and can escape from the 3rd grid. So the answer is 0.

For the second sample test case, BaoBao can change (s_8) to ‘R’ and (s_9) to ‘R’ and escape from the 10th grid. So the answer is 2.

For the third sample test case, BaoBao can change (s_4) to ‘L’ and escape from the 1st grid. So the answer is 1.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值