2018广西省赛

问题 A: Welcome to Collegiate Programming Contest

时间限制: 1 Sec  内存限制: 128 MB
提交: 64  解决: 59
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Welcome to take part in the first Guangxi Province Collegiate Programming Contest hold by Guilin University of Electronic Technology. Programming contest is a contest played by three programmers with one computer to solve some coding problems. Here you need to solve n problems and you certainly wish to AC them all. The contest begins!

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be one line.
there is an integer n, which indicates the number of problems of this contest.
It is guaranteed that——
T is about 100,
for 100% cases, 1 <= n <= 20.

 

 

输出

As for each case, you need to output a single line.
There should be n “AC” in the line separated by n – 1 blanks, as it is shown in the sample.
Please notice that you shouldn’t print extra blank even in the end of the line.

 

样例输入

2
3
4

 

样例输出

AC AC AC
AC AC AC AC

 

[提交][状态]

非常水的题,输出n个AC即可

就不贴代码了

问题 B: Practice

时间限制: 1 Sec  内存限制: 128 MB
提交: 71  解决: 55
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Luras is a contestant of the Guangxi Province Collegiate Programming Contest. And she needs to practice before the contest. It is known that there are n problems in her to do list and every problem has its AC time and AC value. Remember, for each problem, only if Luras has spent all the AC time will she gain the AC value. Now there will be m time to practice. Luras could choose way A: solve problems from shorter AC time to longer AC time; or choose way B: solve problems from bigger value to smaller value. In both way, she must stop practicing once she meets a problem which she could not finish. Now could you tell Luras which way should she choose to gain more AC value during time m?

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be 3 lines.
In the first line, there are 2 integers n m, which indicates the number of to do list problems, the practice time respectively.
In the second line, there are n positive integers which is the array a[] representing the AC time array.
In the third line, there are n positive integers which is the array b[] representing the AC value array.
It is guaranteed that——
T is about 100
for 100% cases, 1 <= n <= 4, 1 <= m <= 100, 1 <= a[i], b[i] <= 20
And it is guaranteed for any i and j (i != j), a[i] != a[j] and b[i] != b[j].

 

输出

As for each case, you need to output a single line.
You need to print “A” if only the way A is better;
You need to print “B” if only the way B is better;
You need to print “SAME” if way A is as good as way B.

 

样例输入

3
3 5
1 2 3
1 2 3
3 4
1 2 3
3 4 5
3 4
1 2 3
3 2 1

 

样例输出

B
A
SAME

 

[提交][状态]

题意:在m的时间里做任务,A的方案是按时间从小到大做,B的方案是按价值从大到小做,求m时间里谁的价值更多

         水题,结构体两次排序,循环即可

代码:

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
struct node
{
    int t,v;
}s[maxn];
bool cmp1(node a,node b){
    return a.t<b.t;
}
bool cmp2(node a,node b){
    return a.v>b.v;
}
int main() {
    int t,n,m;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&n,&m);
        for(int i=1; i<=n; i++)
            scanf("%d",&s[i].t);
        for(int i=1; i<=n; i++)
            scanf("%d",&s[i].v);
        sort(s+1,s+n+1,cmp1);
        int at=0,av=0;
        int bt=0,bv=0;
        for(int i=1; i<=n; i++){
            if(at+s[i].t<=m){
                at+=s[i].t;
                av+=s[i].v;
            }
            else   break;
        }
        sort(s+1,s+n+1,cmp2);
        for(int i=1; i<=n; i++){
            if(bt+s[i].t<=m){
                bt+=s[i].t;
                bv+=s[i].v;
            }
            else  break;
        }
        if(av>bv)  printf("A\n");
        else if(av<bv)   printf("B\n");
        else  printf("SAME\n");
    }
    return 0;
}

问题 C: Team Match

时间限制: 1 Sec  内存限制: 128 MB
提交: 104  解决: 37
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The programming competition not only depends on the programmers, but also directed by the coaches. Mr Z is a coach who direct n players to take part in the Guangxi Province Collegiate Programming Contest. We assume that a team is consisted of 3 players whose ability is x, y, z respectively and x >= y >= z. Then the team’s total ability is 3 * x + 2 * y + 1 * z; And for a team, if its ability is not lower than the gold medal level m, the team will certainly win the gold medal. Mr Z would like to match teams to gain as many gold medals as possible, could you tell him how many gold medals it is?

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be 2 lines.
In the first line, there are 2 integers n m, which indicate the number of players, the gold medal level respectively. Please remember n is always the multiple of 3.
In the second line, there are n integers which represents everyone’s ability.
It is guaranteed that——
T is about 100.
for 100% cases, 1 <= n <= 15, 1 <= m <= 30, 1 <= a[i] <= 20.

 

输出

As for each case, you need to output a single line.
There should be an integer in the line which means the gold medal teams Mr Z could match.

 

样例输入

2
6 18
3 3 3 4 2 2
6 7
1 1 1 1 1 1

 

样例输出

2
0

 

[提交][状态]

题意:在n个数中选 x , y , z ,若 3 * x + 2 * y + z 大于等于m,则答案加一,同时保证 x >= y >= z,每个数只能选一次,保证n一

定是3的倍数

思路:贪心,x从大到小的选,y,z都从小到大的选(但是写了个bug,调不出来,所以队友重新写了)

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100;
int a[maxn];
bool vis[maxn];
bool cmp(int a, int b) { return a > b;}
int main()
{
    int x,y,z;
    int t, n, m;
    scanf("%d", &t);
    while (t--)
    {
        memset(vis, 0, sizeof(vis));
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
        sort(a+1, a+n+1, cmp);
        int ans=0;
        for (int i = 1; i <= n; i++)
        {
            if (vis[i]) continue;
            x=y=z=-1;
            for (int j = i+1; j<=n; j++)
            {
                if (vis[j]) continue;
                for (int k = j+1; k <=n; k++)
                {
                    if (vis[k]) continue;
                    if (a[k]+a[j]*2+a[i]*3 >= m) x=i,y=j,z=k;
                }
            }
            if (x!=-1)
            {
                vis[x] = vis[y] = vis[z] = 1;
                ans++;
            }
            else break;
        }
        printf("%d\n", ans);
    }
    return 0;
}

问题 D: Team Name

时间限制: 1 Sec  内存限制: 128 MB
提交: 48  解决: 29
[提交] [状态] [讨论版] [命题人:admin]

题目描述

After all the teams have been matched, what to do next is of course to think about a nice team name. Now it is known that there are n teams taking part in the Guangxi Province Collegiate Programming Contest. And the name of every team is a string consists of English lower characters. Now Luras needs to get her team name, she doesn’t want the name be any consecutive substring of any other teams. And she prefers shorter names. If there are many choices with the shortest length, she would prefer the one which is the smallest lexicographically. Now could you decide the team name for her?  We regard string a is lexicographically smaller than string b if there exists such index j that a[i] == b[i] for all i < j and a[j] < b[j].

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be n + 1 lines.
In the first line, there is one integer n, which indicates the number of teams.
Then there will be n strings of the next n lines, indicate the name of every team in each line.
It is guaranteed that—— 
T is about 100.
for 100% cases, 1 <= n <= 100, 1 <= |s|(the length of s)<= 30.

 

输出

As for each case, you need to output a single line.
There should be one string in the line which means the name Luras will give to her team.

 

 

样例输入

2
3
a
b
c
2
abcdefghijklmnopqrstuvwxyz
aa

 

样例输出

d
ac

 

[提交][状态]

题意:求一个字符串,尽可能短,同时不是所给任意字符串的子串,若长度相同,则输出字典序最小的

思路:暴力,因为数据小,答案从1的长度开始遍历,按字典序小的顺序,找到第一个不是子串的输出(一开始知道思路,但是想

不到怎么实现,然后队友用了dfs,太菜了)

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=107,m=26;
int n;
char s[N][N],ans[N];
bool f;
void dfs(int d, int len)
{
    if(len==d)
    {
        ans[len++]=0;
        for(int i=0;i<n;i++)
            if(strstr(s[i],ans)) return ;
        f=1;
        return ;
    }
    for(int i=0; i<m; i++)
    {
        ans[d]=i+'a';
        dfs(d+1, len);
        if(f) return ;
    }
    return;
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d",&n);
        for(int i=0; i<n; i++) scanf("%s",s[i]);
        f=0;
        for(int len=1; !f; len++) dfs(0, len);
        printf("%s\n",ans);
    }
    return 0;
}

问题 E: Travel

时间限制: 1 Sec  内存限制: 128 MB
提交: 58  解决: 30
[提交] [状态] [讨论版] [命题人:admin]

题目描述

It is said Guilin's scenery is the best in the world. Now since the first Guangxi Province Collegiate Programming Contest is held in Guilin, Luras decided to travel around Guilin. She knows that there will be n nodes in the travel map. Luras will pick a shortest way to go from node 1 to node n. You are a city designer who could decide if there is a bi-directional edge with the length of 1 between every two nodes. And you hope to build the roads to make the shortest path from 1 to n to be as many as possible. Could you tell Luras how many shortest path could it be at most between node 1 and node n in your final city graph?

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be one lines
In the line, there is 1 integer n, which indicates the number of node.
It is guaranteed that——
T is about 100.
for 100% cases, 2 <= n <= 40.

 

 

输出

As for each case, you need to output a single line.
There should be one integer in the line which means the maximum shortest path could be between node 1 and node n.

 

 

样例输入

6
2
3
4
5
6
7

 

样例输出

1
1
2
3
4
6

 

[提交][状态]

题意:求1到n的最短路径的最多条数,据队友口述,没看题,也没写这个

思路:大概是n-2个点尽量分成3的倍数

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qmod(int n)
{
    ll ans=1;
    for(int i=0; i<n; i++) ans*=3;
    return ans;
}
int main()
{
    //freopen("out.txt","w",stdout);
    int T;
    ll n,ans;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&n);
        if(n==3) puts("1");
        else
        {
            n-=2;
            if(n%3==0) ans=qmod(n/3);
            else if(n%3==1) ans=qmod((n-4)/3)*4;
            else ans=qmod((n-2)/3)*2;
            printf("%lld\n",ans);
        }
    }
    return 0;
}

问题 F: Stadium

时间限制: 1 Sec  内存限制: 128 MB
提交: 59  解决: 29
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Before the contest, of course, we should arrange the field first. As the first Guangxi Province Collegiate Programming Contest, the organizer intends to arrange the site as a trapezoidal building. The four sides of the trapezoid are known as a, b, c and d, and if there are many cases, it is the largest area one. Can you figure out the area of this trapezoid?

 

输入

The first line is an integer T which indicates the case number.
And as for each case,
the first line are four integers a, b, c, d which indicates the four sides of the trapezoid.
It is guaranteed that——
T is about 100.
for 100% cases, 1 <= a, b, c, d <= 10000, and a, b, c, d are all different.

 

 

输出

As for each case, you need to output a single line.
There should be an “IMPOSSIBLE” in the line if the four sides can’t form a trapezoid,
or you should output one real number, and round off two decimal places, represents the largest area of the trapezoid.
Assume the answer is ans, you could print by using function printf("%.2f\n", ans); in C++ and some similar functions in other languages.

 

样例输入

3
1 2 3 4
1 2 3 5
1 2 3 6

 

样例输出

4.71
4.36
IMPOSSIBLE

 

[提交][状态]

题意:给四条边,确定能不能组成梯形,能的话求最大面积

思路:数学题,判断条件是两腰差 < 两底差,两腰和 > 两底差,计算面积是分割成一个三角形一个平行四边形计算

代码:

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int maxn = 100;
int s[10];
 
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d%d%d", &s[1], &s[2], &s[3], &s[4]);
        double ans = 0;
        int da = 0;
        int a, b, c, d;
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j <= 4; j++) {
                if (j == i) continue;
                da = abs(s[i] - s[j]);
                if(da==0)  continue;
                a=min(s[i],s[j]);
                b=max(s[i],s[j]);
                for (int k = 1; k <= 4; k++) {
                    if (k == i || k == j) continue;
                    c = s[k];
                    for (int kk = 1; kk <= 4; kk++) {
                        if (kk == i || kk == j || kk == k) continue;
                        d = s[kk];
                    }
                    if (c+d > da && abs(c-d) < da) {
                        double p = (c+d+da)*1.0/2.0;
                        double s1 = sqrt(p*(p-c)*(p-d)*(p-da));
                        double h = s1*2.0/(da*1.0);
                        double s2 = h * a;
                        ans = max(ans,s1+s2);
                    }
                }
 
            }
        }
        if(ans==0)  printf("IMPOSSIBLE\n");
        else        printf("%.2lf\n",ans);
    }
    return 0;
}

问题 G: GXBalloons

时间限制: 1 Sec  内存限制: 128 MB
提交: 111  解决: 38
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The competition is going. Besides the players, volunteers are busy too, they need to send colorful balloons to the contestants. It is known that the contestants are in a huge room of cartesian coordinate system whose seats are 1000 rows multiplying 1000 columns. Every seat could be empty or corresponds to a team. For every minute, volunteers should send all the balloons together. The volunteers will be told where to send each balloon to. They would like to work efficiently. For two positions (r1, c1) and (r2, c2), if the absolute value of (x1 - x2) is not bigger than k or the absolute value of (y1 – y2) is not bigger than k, the two balloons will be sent by a same volunteer. Could you decide how many volunteers are needed at least to send all the balloons?

 

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be n + 1 lines.
In the first line, there are 2 integers n k, which indicates the number of balloons and the value k.
Then there will be n lines, in every line, there are 2 integers r c which means this balloon will be sent to the r-th row and the c-th column. Please notice that the position could be the same.
It is guaranteed that——
T is about 100.
for 100% cases, 1 <= n <= 10000, 
1 <= k, r, c<= 1000.

 

 

输出

As for each case, you need to output a single line.
There should be one integer in the line which means the minimum volunteers are needed.

 

样例输入

2
3 5
1 1
10 6
15 20
2 5
1 1
7 7

 

样例输出

1
2

 

 

[提交][状态]

题意:如果给的坐标x 或 y 相减小于等于k,就可以由一个人来送气球,求最少的人数

思路:并差集

代码:

#include<bits/stdc++.h>
const int N=1e4+10;
using namespace std;
typedef long long ll;
 
int n,k;
struct node{
    int x,y,id;
}p[N];
int fa[N];
 
bool cmp1(node a,node b){
    return a.x<b.x;
}
bool cmp2(node a,node b){
    return a.y<b.y;
}
bool check(int a,int b){
    if(abs(p[a].x-p[b].x)<=k||abs(p[a].y-p[b].y)<=k) return 1;
    return 0;
}
int fnd(int x){return x==fa[x]?x:fa[x]=fnd(fa[x]);}
void join(int a,int b){
    int fx=fnd(a),fy=fnd(b);
    if(fx!=fy){
        fa[fx]=fy;
    }
}
 
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++) fa[i]=i;
        for(int i=1;i<=n;i++){
            scanf("%d%d",&p[i].x,&p[i].y);
            p[i].id=i;
        }
        sort(p+1,p+1+n,cmp1);
        for(int i=2;i<=n;i++){
            if(check(i,i-1)){
                join(p[i].id,p[i-1].id);
            }
        }
        sort(p+1,p+1+n,cmp2);
        for(int i=2;i<=n;i++){
            if(check(i,i-1)){
                join(p[i].id,p[i-1].id);
            }
        }
        int cnt=0;
        for(int i=1;i<=n;i++){
            if(fa[i]==i) cnt++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

问题 H: GXBoard

时间限制: 1 Sec  内存限制: 128 MB
提交: 58  解决: 58
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The contest has finished. The work turns into the host now. he needs to read all teams’ names later. We suppose the teams’ names are all single string with only English Characters. Could you help the host to calculate how many English characters should he read in total?

 

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be n + 1 lines.
In the first line, there is 1 integer n, which indicates the number of teams.
Then there will be n strings of the next n lines, indicate the name of every team in each line.
It is guaranteed that——
T is about 100,
for 100% cases, 1 <= n <= 100, 1 <= |s|(the length of s)<= 30.

 

 

输出

As for each case, you need to output a single line.
There should be one integer in the line which means the total number of English characters of all teams.

 

样例输入

2
3
a
bb
ccc
2
ChikenDinner
NoResponse

 

样例输出

6
22

 

[提交][状态]

水题,计算字符串的长度并相加

代码:

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
char s[maxn];
int main() {
    int t,n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        int ans=0;
        while(n--){
            scanf("%s",s);
            ans+=strlen(s);
        }
        printf("%d\n",ans);
    }
    return 0;
}

问题 I: Rank LED

时间限制: 1 Sec  内存限制: 128 MB
提交: 73  解决: 17
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The host has released the rank. Everyone’s rank is shown in the LED screen as our Picture. 
 
You could see the light line of number for ‘0’ to ‘9’ is {6、2、5、5、4、5、6、3、7、6} in the order. Luras would like to modify the position of every light line to make her new rank as small as possible while the new rank is also a positive integer without any leading zeros. What’s more, the total number of light lines should be as same as the beginning. Could you tell Luras what the best result she could modify to?

 

 

输入

The first line is an integer T which indicates the case number.
And as for each case, there will be 2 lines.
There is an integer n in the first line which is the length of the number string.
The 2nd line is a number string which is a non-leading zero big positive integer of length n.
It is guaranteed that——
T is about 100.
for 100% cases, 1 <= n <= 100. strings are all non-leading zero number strings.

 

输出

As for each case, you need to output a single line.
There should be one non-leading zero positive number string in the line which means the best rank Luras could modify to.

 

样例输入

3
1
9
2
99
5
10000

 

样例输出

6
28
2888

 

[提交][状态]

题意:题里给0~9的数定义了新的价值,给定一个数,求一个数使其每一位价值相加和给的数相同并且这个数最小,不含前导0

思路:最大的价值是7,所以先用7确定位数,然后每一位判断不会让位数增加的最小的数

代码:

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int maxn = 200;
const int INF=1e9+7;
int a[10]={6,2,5,5,4,5,6,3,7,6};
string s;
int ans[maxn];
int fun(int x){
   if(x%7==0) return x/7;
   else return x/7+1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n;
    cin>>t;
    while (t--) {
        cin>>n;
        cin>>s;
        int d=0,l=s.length();
        for(int i=0; i<l; i++){
            d+=a[s[i]-'0'];
        }
        int wei=fun(d);
        for(int i=0;i<wei;i++){
            if(!i){
                int v=-1;
                for(int j=1;j<10;j++){
                    if(fun(d-a[j])==wei-i-1&&(v==-1||v>j)){
                        ans[i]=j;
                        v=j;
                    }
                }
                d-=a[v];
            }
            else{
                int v=-1;
                for(int j=0;j<10;j++){
                    if(fun(d-a[j])==wei-i-1&&(v==-1||v>j)){
                        ans[i]=j;
                        v=j;
                    }
                }
                d-=a[v];
            }
        }
        for(int i=0;i<wei;i++) cout<<ans[i];
            cout<<endl;
    }
    return 0;
}

问题 J: Pot

时间限制: 1 Sec  内存限制: 128 MB
提交: 88  解决: 53
[提交] [状态] [讨论版] [命题人:admin]

题目描述

The rank has been released. Luras is unhappy because she has not achieved her desired result. So she wants to throw her responsibility to her teammates, so it is the same with her teammates, they would also throw their responsibility to her. There are n members of her team, each has committed a certain degree of mistakes which is called "pot." And the severity of the error is called the size of the "pot." If the pot sizes of A and B are x and y respectively (we assume x > y), then A can divert attention by blaming B, making the size of his pot becoming x – y instead of x. 
As it is a team, every member would cooperate together to throw their pots in the best orderly way to make the sum of all pots to be as small as possible. Could you help her calculate what the sum is?

 

输入

The first line is an integer T which indicates the case number.
And as for each case,
the first line is an integer n which indicates the number of people in her team,
the second line contains n positive integers, which indicates the size of the pot of each person.
It is guaranteed that——
T is less than 100,
for 100% cases, 1 <= n <= 100. 
1 <= the size of the pot of each person <= 100.

 

 

输出

As for each case, you need to output a single line.
There should be only one integer in the line which indicates the minimum sum of all pots in the end.

 

 

样例输入

5
3
2 4 6
2
12 18
5
45 12 27 30 18
2
1 2
1
9

 

样例输出

6
12
15
2
9

 

[提交][状态]

题意:在给定的数中大的减小的,一直减到没有数比减到的数小

思路:找所有数的最小公因数,然后乘n

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const int inf=0x3f3f3f;
const int N=1e5+7;
int a[N],b[N],ans;
inline int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b, a%b);
}
int main()
{
    int T,n,m;
    scanf("%d",&T);
   // freopen("out.txt","w",stdout);
    while(T--)
    {
        scanf("%d",&n);
        scanf("%d",&a[0]);
        ans=a[0];
        for(int i=1; i<n; i++)
        {
            scanf("%d",&a[i]);
            if(ans==1) continue;
            ans=gcd(ans, a[i]);
       //     printf("%d - \n",ans);
        }
        printf("%d\n",ans*n);
    }
    return 0;
}

 

posted @ 2018-08-31 21:00  任小喵  阅读(324)  评论(0编辑  收藏  举报