The 12th Zhejiang Provincial Collegiate Programming Contest(部分)

本文提供了一系列编程竞赛题目的解决方案,包括寻找数组中的唯一元素、计算团队等级、转换键盘布局等,涉及算法设计与实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A     Ace of Aces

Time Limit: 2 Seconds      Memory Limit: 65536 KB

There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the deep universe that we humans have not discovered yet. This year, the TSAB decided to elect an outstanding member from its elite troops. The elected guy will be honored with the title of "Ace of Aces".

After voting, the TSAB received N valid tickets. On each ticket, there is a number Ai denoting the ID of a candidate. The candidate with the most tickets nominated will be elected as the "Ace of Aces". If there are two or more candidates have the same number of nominations, no one will win.

Please write program to help TSAB determine who will be the "Ace of Aces".

Input

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

The first line contains an integer N (1 <= N <= 1000). The next line contains N integers Ai (1 <= Ai <= 1000).

Output

For each test case, output the ID of the candidate who will be honored with "Ace of Aces". If no one win the election, output "Nobody" (without quotes) instead.

Sample Input
3
5
2 2 2 1 1
5
1 1 2 2 3
1
998
Sample Output
2
Nobody
998



#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

int a[10001];

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,x;
		int ans = 0;
		int mm;
		int maxx = -9999999;
		scanf("%d",&n);
		memset(a,0,sizeof(a));
		for(int i=0;i<n;i++)
		{
			scanf("%d",&x);
			a[x]++;
			if(maxx<a[x])
			{
				maxx = a[x];
			}
		}
		for(int i=0;i<1001;i++)
		{
			if(maxx == a[i])
			{
				ans++;
				mm = i;
			}
		}
		if(ans>1)
		{
			printf("Nobody\n");
		}
		else if(ans == 1)
		{
			printf("%d\n",mm);
		}
	}
	return 0;
}







G     Lunch Time

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The 999th Zhejiang Provincial Collegiate Programming Contest will be held in Marjar University. The canteen of Marjar University is making preparations for this grand competition. The canteen provides a lunch set of three types: appetizer, main course and dessert. Each type has several dishes with different prices for choosing.

Edward is the headmaster of Marjar University. One day, to inspect the quality of dishes, he go to the canteen and decides to choose a median set for his lunch. That means he must choose one dish from each of appetizers, main courses and desserts. Each chosen dish should at the median price among all dishes of the same type.

For example, if there are five dessert dishes selling at the price of 2, 3, 5, 10, 30, Edward should choose the dish with price 5 as his dessert since its price is located at the median place of the dessert type. If the number of dishes of a type is even, Edward will choose the dish which is more expensive among the two medians.

You are given the list of all dishes, please write a program to help Edward decide which dishes he should choose.

Input

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

The first line contains three integers SM and D (1 <= SMD <= 100), which means that there are S dishes of appetizer, M dishes of main course and D dishes of dessert.

Then followed by three parts. The first part contains S lines, the second and the last part contains M and D lines respectively. In each line of the three parts, there is a string and an integer indicating the name and the price of a dish. The name of dishes will only consist of non-whitespace characters with no more than 50 characters. The price of dishes are non-negative integers less than or equal to 1000. All dish names will be distinct.

Output

For each test case, output the total price of the median set, together with the names of appetizer, main course and dessert, separated by a single space.

Sample Input
2
1 3 2
Fresh_Cucumber 4
Chow_Mein 5
Rice_Served_with_Duck_Leg 12
Fried_Vermicelli 7
Steamed_Dumpling 3
Steamed_Stuffed_Bun 4
2 3 1
Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33
West_Lake_Water_Shield_Soup 36
DongPo's_Braised_Pork 54
West_Lake_Fish_in_Vinegar 48
Longjing_Shrimp 188
DongPo's_Crisp 18
Sample Output
15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun
108 West_Lake_Water_Shield_Soup DongPo's_Braised_Pork DongPo's_Crisp





#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct node
{
    int ans;
    char str[110];
} q[10010];

int cmp(const void *a,const void *b)
{
    struct node *aa,*bb;
    aa = (struct node*)a;
    bb = (struct node*)b;
    return aa->ans - bb->ans;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
    	int x,y,z;
    	int sum = 0;
        scanf("%d%d%d",&x,&y,&z);
        for(int i=0; i<x; i++)
        {
            scanf("%s%d",q[i].str,&q[i].ans);
        }
        char strx[110],stry[110],strz[110];
        qsort(q,x,sizeof(q[0]),cmp);
        int xx = x/2;
        strcpy(strx,q[xx].str);
        sum += q[xx].ans;
        for(int i=0; i<y; i++)
        {
            scanf("%s%d",q[i].str,&q[i].ans);
        }
        qsort(q,y,sizeof(q[0]),cmp);
        int yy = y/2;
        strcpy(stry,q[yy].str);
        sum += q[yy].ans;
        for(int i=0; i<z; i++)
        {
            scanf("%s%d",q[i].str,&q[i].ans);
        }
        qsort(q,z,sizeof(q[0]),cmp);
        int zz = z/2;
        strcpy(strz,q[zz].str);
        sum += q[zz].ans;
        printf("%d %s %s %s\n",sum,strx,stry,strz);
    }
    return 0;
}







H       May Day Holiday

Time Limit: 2 Seconds      Memory Limit: 65536 KB

As a university advocating self-learning and work-rest balance, Marjar University has so many days of rest, including holidays and weekends. Each weekend, which consists of Saturday and Sunday, is a rest time in the Marjar University.

The May Day, also known as International Workers' Day or International Labour Day, falls on May 1st. In Marjar University, the May Day holiday is a five-day vacation from May 1st to May 5th. Due to Saturday or Sunday may be adjacent to the May Day holiday, the continuous vacation may be as long as nine days in reality. For example, the May Day in 2015 is Friday so the continuous vacation is only 5 days (May 1st to May 5th). And the May Day in 2016 is Sunday so the continuous vacation is 6 days (April 30th to May 5th). In 2017, the May Day is Monday so the vacation is 9 days (April 29th to May 7th). How excited!

Edward, the headmaster of Marjar University, is very curious how long is the continuous vacation containing May Day in different years. Can you help him?

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case, there is an integer y (1928 <= y <= 9999) in one line, indicating the year of Edward's query.

Output

For each case, print the number of days of the continuous vacation in that year.

Sample Input
3
2015
2016
2017
Output
5
6
9




#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int a[10001];
void  Init()
{
    int i,h;
    h=3;
    a[2018]=2;
    for(i=1929;i<=10000;i++)
    {

     if((i%4==0&&i%100!=0)||i%400==0)
     {
        h++;
        a[i]=h%7;
     }
     a[i]=h%7;
     h++;

    }
}
int main()
{
    Init();
    int n;
    int T;
    scanf("%d",&T);

    while(T--)
    {
        scanf("%d",&n);

        if(a[n]==1)
        {
            printf("%d\n",9);
        }
         else if(a[n]==2)
        {
            printf("%d\n",6);
        }
         else if(a[n]==3)
        {
            printf("%d\n",5);
        }
         else if(a[n]==4)
        {
            printf("%d\n",5);
        }
         else if(a[n]==5)
        {
            printf("%d\n",5);
        }
        else if(a[n]==6)
        {
            printf("%d\n",5);
        }
        else if(a[n]==0)
        {
            printf("%d\n",6);
        }
    }
    return 0;
}





J       Convert QWERTY to Dvorak

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Edward, a poor copy typist, is a user of the Dvorak Layout. But now he has only a QWERTY Keyboard with a broken Caps Lock key, so Edward never presses the broken Caps Lock key. Luckily, all the other keys on the QWERTY keyboard work well. Every day, he has a lot of documents to type. Thus he needs a converter to translate QWERTY into Dvorak. Can you help him?

The QWERTY Layout and the Dvorak Layout are in the following:

Qwerty Layout
The QWERTY Layout

Dvorak Layout
The Dvorak Layout

Input

A QWERTY document Edward typed. The document has no more than 100 kibibytes. And there are no invalid characters in the document.

Output

The Dvorak document.

Sample Input
Jgw Gqm Andpw a H.soav Patsfk f;doe
Nfk Gq.d slpt a X,dokt vdtnsaohe
Kjd yspps,glu pgld; aod yso kd;kgluZ
1234567890
`~!@#$%^&*()}"']_+-=ZQqWEwe{[\|
ANIHDYf.,bt/
ABCDEFuvwxyz
Sample Output
Hi, I'm Abel, a Dvorak Layout user.
But I've only a Qwerty keyboard.
The following lines are for testing:
1234567890
`~!@#$%^&*()+_-={}[]:"'<>,.?/\|
ABCDEFuvwxyz
AXJE>Ugk,qf;




#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
using namespace std;
char str[1000001];
int main()
{
	while(gets(str)!=NULL)
		{
		int len = strlen(str);
		for(int i=0;i<len;i++)
		{
			switch(str[i])
			{
				case '_':printf("{");break;
				case '+':printf("}");break;
				case '`':printf("`");break;
				case '1':printf("1");break;
				case '2':printf("2");break;
				case '3':printf("3");break;
				case '4':printf("4");break;
				case '5':printf("5");break;
				case '6':printf("6");break;
				case '7':printf("7");break;
				case '8':printf("8");break;
				case '9':printf("9");break;
				case '0':printf("0");break;
				case '-':printf("[");break;
				case '=':printf("]");break;
				case 'q':printf("'");break;
				case 'w':printf(",");break;
				case 'e':printf(".");break;
				case 'r':printf("p");break;
				case 't':printf("y");break;
				case 'y':printf("f");break;
				case 'u':printf("g");break;
				case 'i':printf("c");break;
				case 'o':printf("r");break;
				case 'p':printf("l");break;
				case '{':printf("?");break;
				case '}':printf("+");break;
				case '|':printf("|");break;
			case '\\':printf("\\");break;
				case '[':printf("/");break;
				case ']':printf("=");break;
			case 'Q':printf("\"");break;
				case 'W':printf("<");break;
				case 'E':printf(">");break;
				case 'R':printf("P");break;
				case 'T':printf("Y");break;
				case 'Y':printf("F");break;
				case 'U':printf("G");break;
				case 'I':printf("C");break;
				case 'a':printf("a");break;
				case 'S':printf("O");break;
				case 's':printf("o");break;
				case 'D':printf("E");break;
				case 'F':printf("U");break;
				case 'G':printf("I");break;
				case 'H':printf("D");break;
				case 'O':printf("R");break;
				case 'P':printf("L");break;
				case 'A':printf("A");break;
				case 'J':printf("H");break;
				case 'K':printf("T");break;
				case 'L':printf("N");break;
				case 'd':printf("e");break;
				case 'f':printf("u");break;
				case 'g':printf("i");break;
				case 'h':printf("d");break;
				case 'j':printf("h");break;
				case 'k':printf("t");break;
				case 'l':printf("n");break;
				case ':':printf("S");break;
				case ';':printf("s");break;
				case '"':printf("_");break;
		                case '\'':printf("-");break;
				case 'Z':printf(":");break;
				case 'X':printf("Q");break;
				case 'C':printf("J");break;
				case 'V':printf("K");break;
				case 'B':printf("X");break;
				case 'N':printf("B");break;
				case 'M':printf("M");break;
				case 'z':printf(";");break;
				case 'x':printf("q");break;
				case 'c':printf("j");break;
				case 'v':printf("k");break;
				case 'b':printf("x");break;
				case 'n':printf("b");break;
				case 'm':printf("m");break;
				case '<':printf("W");break;
				case '>':printf("V");break;
				case ',':printf("w");break;
				case '.':printf("v");break;
				case '?':printf("Z");break;
				case '/':printf("z");break;
				case ' ':printf(" ");break;
		                default : printf("%c",str[i]);
			}

		}printf("\n");
	}
	return 0;
}






L      Demacia of the Ancients

Time Limit: 2 Seconds      Memory Limit: 65536 KB

There is a popular multiplayer online battle arena game called Demacia of the Ancients. There are lots of professional teams playing this game. A team will be approved as Level K if there are exact K team members whose match making ranking (MMR) is strictly greater than 6000.

You are given a list of teams. Please calculate the level of each team.

Input

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

The first line contains an integer N (1 <= N <= 10) indicating the number of team members.

The second line contains N integers representing the MMR of each team member. All MMRs are non-negative integers less than or equal to 9999.

Output

For each test case, output the level of the given team.

Sample Input
3
5
7986 6984 6645 6200 6150
5
7401 7377 6900 6000 4300
3
800 600 200
Sample Output
5
3
0



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

int main()
{
   int T;
   scanf("%d",&T);
   while(T--)
   {
       int a[1001];
       int n;
       scanf("%d",&n);
       for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
       int ans=0;
       for(int i=0;i<n;i++)
         if(a[i]>6000) ans++;
         printf("%d\n",ans);
   }
    return 0;
}

D       Beauty of Array

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Edward has an array A with N integers. He defines the beauty of an array as the summation of all distinct integers in the array. Now Edward wants to know the summation of the beauty of all contiguous subarray of the array A.

Input

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

The first line contains an integer N (1 <= N <= 100000), which indicates the size of the array. The next line contains N positive integers separated by spaces. Every integer is no larger than 1000000.

Output

For each case, print the answer in one line.

Sample Input
3
5
1 2 3 4 5
3
2 3 3
4
2 3 3 2
Sample Output
105
21
38





#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>

using namespace std;

int a[100010];
int v[1001000];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        long long int n;
        memset(v,0,sizeof(v));
        long long int sum = 0;
        int k = 1;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum += (n-i+1)*k*a[i];
            if(v[a[i]])
            {
                sum -= v[a[i]] * (n-i+1)*a[i];
            }
            v[a[i]] = i;
            k++;
        }
        printf("%lld\n",sum);
    }
    return 0;
}



截至目前,尚未有2024年四川省级大学生程序设计竞赛的具体题目或题解公开发布。然而,可以基于以往的比赛内容推测可能涉及的类型和主题。 通常情况下,四川省大学生程序设计竞赛(Sichuan Provincial Collegiate Programming Contest)中的A题往往是一个相对基础但具有挑战性的算法问题,旨在测试参赛者的逻辑思维能力和编程技巧。例如,在2021年的比赛中,A题“Chuanpai”的核心在于通过模拟来处理周期性变化的行为模式[^3]。 对于类似的题目,解决的关键通常是识别并利用某种规律或者周期特性来进行高效计算。以下是针对该类问题的一个通用解决方案框架: ### 解决方案框架 假设未来某道A题涉及到周期行为的变化,则可以通过如下方式实现其基本逻辑: #### 周期检测与状态更新 ```python def simulate_rounds(people, preferences): rounds = 0 while not is_stable_state(people): # 判断当前状态是否稳定 update_people_based_on_preferences(people, preferences) # 更新每个人的状态 rounds += 1 return rounds, people def is_stable_state(people): # 定义稳定性条件 pass def update_people_based_on_preferences(people, preferences): n = len(preferences) new_people = [] for i in range(n): if (preferences[i] % 2 == 0 and i % 2 == 0) or \ (preferences[i] % 2 != 0 and i % 2 != 0): new_people.append(add_dish(people[i])) else: new_people.append(eat_dish(people[i])) global people people = new_people[:] def add_dish(person): person['dishes'] += 1 return person def eat_dish(person): if person['dishes'] > 0: person['dishes'] -= 1 return person ``` 上述代码片段展示了如何根据偏好列表`preferences`动态调整人员数组`people`的状态,并持续迭代直到达到某个稳定的终止条件为止。 尽管目前无法确切得知2024年度的确切考题细节,但从过往经验来看,比赛倾向于考察选手们对数据结构、算法优化以及边界情况处理的理解程度。 ### 结论 综上所述,虽然具体到2024年的赛事详情尚不可知,但是通过对历年真题的学习研究可以帮助预测可能出现的方向及其应对策略。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值