UESTC 2018 Summer Training #4 Div.2

这次没去考试:就考试结尾场外交题了一道题。B题是补得。

因为和女朋友和好啦 开心 我以后要好好对她 不可以惹她生气了。好好学习。加油!

A

The ACM International Collegiate Programming Contest has been held in Vietnam for more than 1010 years. The contest is a great chance for the students to meet new friends, broaden their knowledge and of course, win prizes.

Every years, universities can send one or multiple teams to the contest and all universities hope to win prizes. The organizers want to define a rule to award the excellent contestants.

The contest director decided to follow the World Finals policy by having 44 first prizes, 44 second prizes and 44 third prizes. 1212 winners out of more than a hundred teams is also a good proportion to recognize the best students.

Since universities can send multiple teams, we don’t want one university to swept all the awards. Thus, only the top team from a university can be awarded. It seems harsh for the second best team from one university but do not worry, they will still receive relevant certificates.

The table below is the result of top 1010 of Nha Trang Regional Contest 2016. The 44 -th (team WINDOWS) and 88 -th place (team UBUNTU) did not receive prizes because they were not the top team from University of Engineering and Technology - VNU. Team Metis and team BK.DeepMind are in the same situation.

Place

Institution

Team

Prize

11

Seoul National University

ACGTeam

First Prize

22

University of Engineering and Technology - VNU

LINUX

First Prize

33

Shanghai Jiao Tong University

Mjolnir

First Prize

44

University of Engineering and Technology - VNU

WINDOWS

 

55

National Taiwan University

PECaveros

First Prize

66

Hanoi University of Science and Technology

BK.Juniors

Second Prize

77

Ho Chi Minh City University of Science

HCMUS-Serendipity

Second Prize

88

University of Engineering and Technology - VNU

UBUNTU

 

99

Shanghai Jiao Tong University

Metis

 

1010

Hanoi University of Science and Technology

BK.DeepMind

 

Given the final scoreboard of the contest, your task is to determine which 1212 teams should be awarded prizes.

Input

  • The input starts with the number of teams NN (12≤N≤20012≤N≤200 ).

  • The ii -th line of the next NN lines contains information about the team that ranks ii : the university name and the team name separated by a single space. Both names consists of digits, lowercase and uppercase English alphabet letters only. Both names does not exceed 2020 letters in length.

  • It is guaranteed that there are at least 1212 different universities.

Output

The output should contain 1212 lines describing 1212 winners. In each line, you should print the university name and the team name separated by a single space. The winners should be listed in the same order as the input.

Sample Input 1Sample Output 1
30
Seoul ACGTeam
VNU LINUX
SJTU Mjolnir
VNU WINDOWS
NTU PECaveros
HUST BKJuniors
HCMUS HCMUSSerendipity
VNU UBUNTU
SJTU Metis
HUST BKDeepMind
HUST BKTornado
HCMUS HCMUSLattis
NUS Tourism
VNU DOS
HCMUS HCMUSTheCows
VNU ANDROID
HCMUS HCMUSPacman
HCMUS HCMUSGeomecry
UIndonesia DioramaBintang
VNU SOLARIS
UIndonesia UIChan
FPT ACceptable
HUST BKIT
PTIT Miners
PSA PSA
DaNangUT BDTTNeverGiveUp
VNU UNIXBSD
CanTho CTUA2LTT
Soongsil Team10deung
Soongsil BezzerBeater

 

Seoul ACGTeam
VNU LINUX
SJTU Mjolnir
NTU PECaveros
HUST BKJuniors
HCMUS HCMUSSerendipity
NUS Tourism
UIndonesia DioramaBintang
FPT ACceptable
PTIT Miners
PSA PSA
DaNangUT BDTTNeverGiveUp

A题很简单,一道HASH题即可。

 

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>

#define MOD 10000000
using namespace std; 
typedef long long LL;
typedef unsigned long long ULL;
ULL base=233;
long long quickpow(long long n, long long base) {
    long long res = 1;
    while(n) {
        if(n & 1) {
            res = res * base % MOD;
        }
        n >>= 1;
        base = base * base % MOD;
    }
    return res;
}//快速幂 
ULL HASH(char s[])
{
	int l=strlen(s);
	ULL ans=0;
	for(int i=0;i<l;i++)
	{
		ans=ans*base+(ULL)s[i];
	}
	return ans;
}
set<ULL>hash0;//手动哈希 



char B[30],C[30];

int main()
{
	ULL hash1; 
	int N;
	cin>>N;
	int SIZE=0;
	while(N--)
	{
		int i=0;
		cin>>B>>C;
		hash1=HASH(B);
		hash0.insert(hash1);
		if(hash0.size()>SIZE)
		{
			SIZE=hash0.size();
            cout<<B<<" "<<C<<endl;
		}
        if(SIZE==12)break;
	}

}

 

 B

The tunnels of Cu Chi are an immense network of underground tunnels connecting rooms located in the Cu Chi District of Ho Chi Minh City. The Cu Chi tunnels were the location of several military campaigns in the 1960s. Nowadays, it is a popular tourist destination.

There are documents from trusted sources about a private network of tunnels in this area used by a secret forces unit but it has not been discovered. According to the documents, this private network has NN rooms (numbered from 11 to NN ) connected by N−1N−1 bidirectional tunnels. Room 11 is the entry point from the ground surface to this underground network. From room 11 , you can follow the tunnels to go to any of the rooms. The rooms are numbered in such a way that, if you follow the shortest path from room 11 to any room XX , the sequence of visited rooms’ indices will be increasing. The image below shows a valid map of this network.

\includegraphics[width=0.5\textwidth ]{example1.png}

The network below is invalid, since the path from 11 to 44 is 11 - 33 - 22 - 44 , which is not increasing:

\includegraphics[width=0.5\textwidth ]{example2.png}

There is also an old article from an unknown source mentioning about DiDi which is the number of rooms directly connected to room ii .

Given an array DD of size NN , your task is to verify if it is possible to have such a network.

Input

  • The first line contains an integer NN - the number of rooms in the network (2≤N≤1000)(2≤N≤1000) .

  • The second line consists of NN integers DiDi - the number of rooms that are directly connected to room ii (1≤Di≤N−1)(1≤Di≤N−1) .

Output

Print YES/NO if it is possible/impossible to have such a network, respectively.

Sample Input 1Sample Output 1
8
3 2 2 1 1 3 1 1
YES
Sample Input 2Sample Output 2
4
3 3 3 3
NO

 贪心题:主要不断加入尽可能小的且能加入的点(度数满足要求),没加入一次,两个点都减少1个度数,并把新的点加入图中(这里用set存图),加入的就map=1,以免下次使用的时候又把这个点加上了:比如第二层是2、3、4,2往下又加上了5、6,但是3往下也可以加5、6,但已经被加上了就不能加了。

最后判断度数是否都为0,中间有些情况可以提前结束判断。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>

#define MOD 10000000

using namespace std; 
typedef long long LL;
typedef unsigned long long ULL;
ULL base=233;
long long quickpow(long long n, long long base) {
    long long res = 1;
    while(n) {
        if(n & 1) {
            res = res * base % MOD;
        }
        n >>= 1;
        base = base * base % MOD;
    }
    return res;
}//快速幂 
ULL HASH(char s[])
{
	int l=strlen(s);
	ULL ans=0;
	for(int i=0;i<l;i++)
	{
		ans=ans*base+(ULL)s[i];
	}
	return ans;
}
set<ULL>hash0;//手动哈希 
set<ULL>::iterator it;//STL迭代器 



int A[1010];
set< int >set0;
map<int,int>map0;
int main()
{
	int N;
	cin>>N;
	for(int i=1;i<=N;i++)
    {
    	cin>>A[i];
    	map0[i]=0;
    }
    set0.insert(1);
    while(!set0.empty())
    {
    	int k=*set0.begin();
    	set0.erase(k);
    	if(A[k]>0)
    	for(int i=k+1;i<=N;i++)
    	{
	    	if(A[i]>=1&&map0[i]==0)
	    	{
	    		A[k]--;
	    		A[i]--;
	    		set0.insert(i);
	    		map0[i]=1;
	    	}
	    	if(A[k]==0)break;
	    }
	    if(A[k]>0)break;
    }
    for(int i=1;i<=N;i++)
    {
    	if(A[i]!=0){cout<<"NO"<<endl;return 0;}
    }
    cout<<"YES"<<endl;
}

E

Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.

There is a sequence a that consists of n integers a1, a2, ..., an. Let's denote f(l, r, x) the number of indices k such that: l ≤ k ≤ r and ak = x. His task is to calculate the number of pairs of indicies i, j (1 ≤ i < j ≤ n) such that f(1, i, ai) > f(j, n, aj).

Help Pashmak with the test.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 106). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a single integer — the answer to the problem.

Examples

Input

7
1 2 1 1 2 2 1

Output

8

Input

3
1 1 1

Output

1

Input

5
1 2 3 4 5

Output

0

E题是一道对我来说的一个总结性很强的题:有单独讲:https://blog.csdn.net/mxYlulu/article/details/81137457

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值