Qualification Round 2020 - Code Jam 2020

Vestigium

Problem
Vestigium means “trace” in Latin. In this problem we work with Latin squares and matrix traces.

The trace of a square matrix is the sum of the values on the main diagonal (which runs from the upper left to the lower right).

An N-by-N square matrix is a Latin square if each cell contains one of N different values, and no value is repeated within a row or a column. In this problem, we will deal only with “natural Latin squares” in which the N values are the integers between 1 and N.

Given a matrix that contains only integers between 1 and N, we want to compute its trace and check whether it is a natural Latin square. To give some additional information, instead of simply telling us whether the matrix is a natural Latin square or not, please compute the number of rows and the number of columns that contain repeated values.

Input
The first line of the input gives the number of test cases, T. T test cases follow. Each starts with a line containing a single integer N: the size of the matrix to explore. Then, N lines follow. The i-th of these lines contains N integers Mi,1, Mi,2 …, Mi,N. Mi,j is the integer in the i-th row and j-th column of the matrix.

Output
For each test case, output one line containing Case #x: k r c, where x is the test case number (starting from 1), k is the trace of the matrix, r is the number of rows of the matrix that contain repeated elements, and c is the number of columns of the matrix that contain repeated elements.

Limits
Test set 1 (Visible Verdict)
Time limit: 20 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.
2 ≤ N ≤ 100.
1 ≤ Mi,j ≤ N, for all i, j.

Solution

#include<bits/stdc++.h>
using namespace std;
int a[110][110];
bool r[110], c[110];
map<int,int> mp;
int main(int argc,char *argv[]){
    int t, n, ans = 0;
    int p1, p2, p3;

    scanf("%d",&t);
    for(int k = 1;k <= t;k ++){
        memset(r,0,sizeof(r));
        memset(c,0,sizeof(c));
        p1 = 0;p2 = 0;p3 = 0;
        scanf("%d",&n);
        for(int i = 1;i <= n;i ++){
            for(int j = 1;j <= n;j ++){
                scanf("%d",&a[i][j]);
                if(i == j)p1 += a[i][j];
            }
        }
        mp.clear();
        for(int i = 1;i <= n;i ++){
            for(int j = 1;j <= n;j ++){
                if(mp[a[i][j]]){
                    c[i] = true;
                    break;
                }
                mp[a[i][j]] ++;
            }
            mp.clear();
        }
        for(int i = 1;i <= n;i ++){
            for(int j = 1;j <= n;j ++){
                if(mp[a[j][i]]){
                    r[i] = true;
                    break;
                }
                mp[a[j][i]] ++;
            }
            mp.clear();
        }
        for(int i = 1;i <= n;i ++){
            if(r[i])p2 ++;
            if(c[i])p3 ++;
        }
        printf("Case #%d: %d %d %d\n",k,p1,p3,p2);
    }
    return 0;
}

Nesting Depth

Problem
Given a string of digits S, insert a minimum number of opening and closing parentheses into it such that the resulting string is balanced and each digit d is inside exactly d pairs of matching parentheses.

Let the nesting of two parentheses within a string be the substring that occurs strictly between them. An opening parenthesis and a closing parenthesis that is further to its right are said to match if their nesting is empty, or if every parenthesis in their nesting matches with another parenthesis in their nesting. The nesting depth of a position p is the number of pairs of matching parentheses m such that p is included in the nesting of m.

For example, in the following strings, all digits match their nesting depth: 0((2)1), (((3))1(2)), ((((4)))), ((2))((2))(1). The first three strings have minimum length among those that have the same digits in the same order, but the last one does not since ((22)1) also has the digits 221 and is shorter.

Given a string of digits S, find another string S’, comprised of parentheses and digits, such that:
all parentheses in S’ match some other parenthesis,
removing any and all parentheses from S’ results in S,
each digit in S’ is equal to its nesting depth, and
S’ is of minimum length.

Input
The first line of the input gives the number of test cases, T. T lines follow. Each line represents a test case and contains only the string S.

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 string S’ defined above.

Limits
Time limit: 20 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.
1 ≤ length of S ≤ 100.

Solution
这道题我格式错误WA了一发,就因为少加个空格QAQ

#include<bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << '\n'
using namespace std;
string a;
int s[111];
int main(int argc,char *argv[]){
    int t;
    scanf("%d",&t);
    for(int i = 1;i <= t;i ++){
        cin >> a;
        int len = a.length();
        a = "0" + a + "0";
        for(int i = 1;i <= len + 1;i ++){
            s[i] = a[i] - a[i - 1];
        }
        printf("Case #%d: ", i);
        for(int i = 1;i <= len + 1;i ++){
            if(s[i] > 0)for(int j = 0;j < s[i];j ++)printf("(");
            if(s[i] < 0)for(int j = 0;j > s[i];j --)printf(")");
            if(i != len + 1)cout << a[i];
        }
        cout << '\n';
    }
}

Parenting Partnering Returns
Problem
Cameron and Jamie’s kid is almost 3 years old! However, even though the child is more independent now, scheduling kid activities and domestic necessities is still a challenge for the couple.

Cameron and Jamie have a list of N activities to take care of during the day. Each activity happens during a specified interval during the day. They need to assign each activity to one of them, so that neither of them is responsible for two activities that overlap. An activity that ends at time t is not considered to overlap with another activity that starts at time t.

For example, suppose that Jamie and Cameron need to cover 3 activities: one running from 18:00 to 20:00, another from 19:00 to 21:00 and another from 22:00 to 23:00. One possibility would be for Jamie to cover the activity running from 19:00 to 21:00, with Cameron covering the other two. Another valid schedule would be for Cameron to cover the activity from 18:00 to 20:00 and Jamie to cover the other two. Notice that the first two activities overlap in the time between 19:00 and 20:00, so it is impossible to assign both of those activities to the same partner.

Given the starting and ending times of each activity, find any schedule that does not require the same person to cover overlapping activities, or say that it is impossible.

Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line containing a single integer N, the number of activities to assign. Then, N more lines follow. The i-th of these lines (counting starting from 1) contains two integers Si and Ei. The i-th activity starts exactly Si minutes after midnight and ends exactly Ei minutes after midnight.

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 IMPOSSIBLE if there is no valid schedule according to the above rules, or a string of exactly N characters otherwise. The i-th character in y must be C if the i-th activity is assigned to Cameron in your proposed schedule, and J if it is assigned to Jamie.

If there are multiple solutions, you may output any one of them. (See “What if a test case has multiple correct solutions?” in the Competing section of the FAQ. This information about multiple solutions will not be explicitly stated in the remainder of the 2020 contest.)

Limits
Time limit: 20 seconds per test set.
Memory limit: 1GB.
1 ≤ T ≤ 100.
0 ≤ Si < Ei ≤ 24 × 60.

Test set 1 (Visible Verdict)
2 ≤ N ≤ 10.

Test set 2 (Visible Verdict)
2 ≤ N ≤ 1000.

Solution

#include<bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << '\n'
using namespace std;
struct node{
	int l, r;
	int order;
	char c;
}a[1011];
bool cmp1(node a,node b){
	return a.l<b.l;
}
bool cmp2(node a,node b){
	return a.order<b.order;
}
int main(int argc,char *argv[]){
	int t, n;
	cin >> t;
	for(int i = 1;i <= t;i++)
	{
		int cc = 0,jj = 0,f = 1;
		scanf("%d",&n);
		for(int j = 0;j < n;j ++){
			scanf("%d%d", &a[j].l, &a[j].r);
			a[j].order=j;
		}
		sort(a,a+n,cmp1);
		for(int j = 0; j < n; j ++){
			if(cc <= a[j].l){
				cc = a[j].r;
				a[j].c = 'C';
			}
			else if(jj <= a[j].l){
				jj = a[j].r;
				a[j].c = 'J';
			}
			else{
				f = 0;
				break;
			}
		}
	    printf("Case #%d: ",i);
	    if(f == 0)printf("IMPOSSIBLE\n",i);
		else{
			sort(a,a + n,cmp2);
			for(int j = 0;j < n;j ++)printf("%c",a[j].c);
			printf("\n");
		}
	}
	return 0;
}

由于30+分就qualified了,就不做了(主要是不会)(留下了蒟蒻的泪水QAQ)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
extra qualification timerevent是指额外的资格和时间活动。这是一个广泛的概念,可以指任何一种能够增加个人技能和知识的额外资格或时间活动。 在职场中,个人可以通过参加专业培训课程、研讨会和工作坊来获取额外的资格和时间活动。这些活动可以为他们提供新的技能和知识,使他们在职场中更加具有竞争力。此外,个人还可以通过参加行业认证考试来获得额外的资格,这些认证可以证明他们具备特定领域的专业知识和技能。通过参与这些额外的资格和时间活动,个人可以增加自己在职场中的价值和机会。 在教育领域,学生可以通过参加额外的课外培训活动来提高自己的学术水平和技能。这些活动可以包括参加学术竞赛、科研项目、社会实践等,这些活动可以拓宽学生的眼界,培养他们的创造力和领导能力。此外,学生还可以通过参加语言培训班、艺术培训班等增加自己的技能和知识。这些额外的资格和时间活动可以为学生提供更多的机会,帮助他们在学术和职业领域取得成功。 总的来说,额外的资格和时间活动对个人和学生来说都是非常有益的。这些活动可以帮助他们提高自己的技能和知识,增加他们在职场和学术领域的竞争力。而且,额外的资格和时间活动也能为个人提供更多的机会和发展空间。因此,我们鼓励每个人都参与额外的资格和时间活动,不断提升自己。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值