码迷,mamicode.com
首页 > 其他好文 > 详细

BestCoder 2nd Anniversary

时间:2016-07-19 10:37:29      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:


A--Oracle

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 242    Accepted Submission(s): 103


Problem Description
There is once a king and queen, rulers of an unnamed city, who have three daughters of conspicuous beauty.

The youngest and most beautiful is Psyche, whose admirers, neglecting the proper worship of the love goddess Venus, instead pray and make offerings to her. Her father, the king, is desperate to know about her destiny, so he comes to the Delphi Temple to ask for an oracle.

The oracle is an integer n without leading zeroes. 

To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leading zeroes</b>, and their sum should be as large as possible. 

Help him to work out the maximum sum. It might be impossible to do that. If so, print `Uncertain`.
 

Input
The first line of the input contains an integer T (1T10), which denotes the number of test cases.

For each test case, the single line contains an integer n (1n<1010000000).
 

Output
For each test case, print a positive integer or a string `Uncertain`.
 

Sample Input
3 112 233 1
 

Sample Output
22 35 Uncertain
Hint
In the first example, it is optimal to split $ 112 $ into $ 21 $ and $ 1 $, and their sum is $ 21 + 1 = 22 $. In the second example, it is optimal to split $ 233 $ into $ 2 $ and $ 33 $, and their sum is $ 2 + 33 = 35 $. In the third example, it is impossible to split single digit $ 1 $ into two parts.
 

Source


问题描述
曾经有一位国王,统治着一片未名之地。他膝下有三个女儿。

三个女儿中最年轻漂亮的当属Psyche。她的父亲不确定她未来的命运,于是他来到Delphi神庙求神谕。

神谕可以看作一个不含前导零的正整数nn。

为了得到真正的预言,他可以将nn的各个数位重新排列,并将其分成两个不含前导零的正整数。

请你帮助他求出这两个正整数最大的和。如果不存在这样的两个正整数,输出"Uncertain".
输入描述
第一行一个整数TT (1 \le T \le 10)(1T10),代表数据组数。

接下来TT行,每行一个正整数nn (1 \le n < 10 ^ {10000000})(1n<10?10000000??)
输出描述
对于每组数据,输出一个整数表示最大的和。若不存在一种方案,输出"Uncertain".
输入样例
3
112
233
1
输出样例
22
35
Uncertain
Hint
对于第一组数据,最优方案是将112112分成212111,最大的和为21 + 1 = 2221+1=22。

对于第二组数据,最优方案是将233233分成223333,最大的和为2 + 33 = 352+33=35。

对于第三组数据,显然无法将一个数位分成两部分。

建议使用效率较高的读入方式。



代码:

#include<cstdio>
#include<cstring>
char shu[10000100];
int zui[10000100];
int main()
{
    int t;scanf("%d",&t);
    while (t--)
    {
        scanf("%s",shu);
        int ll=strlen(shu);
        int ge[10]={0};
        memset(zui,0,sizeof(zui));
        for (int i=0;i<ll;i++)
        ge[shu[i]-'0']++;
        if (ge[0]>ll-2)
        {
            printf("Uncertain\n");
            continue;
        }
        int kp;
        for (int i=1;i<10;i++)
        {
            if (ge[i])
            {
                kp=i;
                ge[i]--;
                break;
            }
        }
        int llp=0;
        for (int i=0;i<10;i++)
        {
            if (ge[i])
            {
                while (ge[i]--)
                zui[llp++]=i;
            }
        }
        zui[0]+=kp;
        llp=ll-2;
        for (int i=0;i<=llp;i++)
        {
            if (zui[i]>9)
            {
                zui[i]-=10;
                zui[i+1]++;
                if (i==llp)
                llp++;
            }
        }
        for (int i=llp;i>=0;i--)
        printf("%d",zui[i]);
        printf("\n");
    }
    return 0;
}






B--Arrange

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 209    Accepted Submission(s): 79


Problem Description
Accidentally, Cupid, god of desire has hurt himself with his own dart and fallen in love with Psyche. 

This has drawn the fury of his mother, Venus. The goddess then throws before Psyche a great mass of mixed crops.

There are n heaps of crops in total, numbered from 1 to n

Psyche needs to arrange them in a certain order, assume crops on the i-th position is Ai.

She is given some information about the final order of the crops:

1. the minimum value of A1,A2,...,Ai is Bi.

2. the maximum value of A1,A2,...,Ai is Ci.

She wants to know the number of valid permutations. As this number can be large, output it modulo 998244353.

Note that if there is no valid permutation, the answer is 0.
 

Input
The first line of input contains an integer T (1T15), which denotes the number of testcases.

For each test case, the first line of input contains single integer n (1n105).

The second line contains n integers, the i-th integer denotes Bi (1Bin).

The third line contains n integers, the i-th integer denotes Ci (1Cin).
 

Output
For each testcase, print the number of valid permutations modulo 998244353.
 

Sample Input
2 3 2 1 1 2 2 3 5 5 4 3 2 1 1 2 3 4 5
 

Sample Output
1 0
Hint
In the first example, there is only one valid permutation (2,1,3) . In the second example, it is obvious that there is no valid permutation.
 

Source


问题描述
Cupid一不小心将爱情之箭射到了自己,他爱上了Psyche。

这引起了他的母亲Venus的注意。Venus将Psyche带到了一堆打乱的谷堆旁。

这儿共有nn堆稻谷,编号为11nn。Psyche需要将这些谷堆以某种顺序排列,设最终排在第ii位的谷堆是A_iA?i??。

她得知了一些该排列的要求:

  1. 对于任意整数i \in [1,n]i[1,n]A_1, A_2, ..., A_iA?1??,A?2??,...,A?i??的最小值为B_iB?i??。

  2. 对于任意整数i \in [1,n]i[1,n]A_1, A_2, ..., A_iA?1??,A?2??,...,A?i??的最大值为C_iC?i??。

现在Psyche想知道,共有多少种合法的排列。由于答案可能很大,输出时对998244353998244353取模。
输入描述
第一行,一个整数TT (1 \le T \le 15)(1T15),代表数据组数。

对于每组数据,第一行有一个整数nn (1 \le n \le 10 ^ 5)(1n10?5??),代表排列大小。

第二行,nn个整数,第ii个整数为B_iB?i?? (1 \le B_i \le n)(1B?i??n)。

第三行,nn个整数,第ii个整数为C_iC?i?? (1 \le C_i \le n)(1C?i??n)
输出描述
输出TT行,对于每组数据输出答案对998244353998244353取模的结果。
输入样例
2
3
2 1 1
2 2 3
5
5 4 3 2 1
1 2 3 4 5
输出样例
1
0
Hint
对于第一组数据,只有一种合法的排列(2,1,3)(2,1,3)。

对于第二组数据,没有合法的排列。


代码:


#include<cstdio>
#include<cstring>
int n,mi,ma,bi[100100],ci[100100];
__int64 s,cha;
int main()
{
	int t;scanf("%d",&t);
	while (t--)
	{
		scanf("%d",&n);
		for (int i=0;i<n;i++)
		scanf("%d",&bi[i]);
		for (int i=0;i<n;i++)
		scanf("%d",&ci[i]);
		bool fafe=true;
		if (ci[0]!=bi[0])
		{
			printf("0\n");
			continue;
		}
		mi=ma=bi[0];cha=0;s=1;
		for (int i=1;i<n;i++)
		{
			if (bi[i]!=mi&&ci[i]!=ma)
			{
				fafe=false;
				break;
			}
			if (bi[i]>mi||ci[i]<ma)
			{
				fafe=false;
				break;
			}
			if (bi[i]==mi&&ci[i]==ma)
			{
				if (cha<1)
				{
					fafe=false;
				    break;
				}
		//		printf("%I64d        66\n",cha);
				s*=cha;
				cha--;
				s%=998244353;
			}
			else if (bi[i]!=mi)
			{
				cha+=mi-bi[i]-1;
				mi=bi[i];
			}
			else
			{
				cha+=ci[i]-ma-1;
				ma=ci[i];
			}
		}
		if (fafe)
		printf("%I64d\n",s);
		else
		printf("0\n");
	}
	return 0;
}







C--Wool

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 139    Accepted Submission(s): 43


Problem Description
At dawn, Venus sets a second task for Psyche.

She is to cross a river and fetch golden wool from violent sheep who graze on the other side.

The sheep are wild and tameless, so Psyche keeps on throwing sticks to keep them away. 

There are n sticks on the ground, the length of the i-th stick is ai.

If the new stick she throws forms a triangle with any two sticks on the ground, the sheep will be irritated and attack her. 

Psyche wants to throw a new stick whose length is within the interval [L,R]. Help her calculate the number of valid sticks she can throw next time.
 

Input
The first line of input contains an integer T (1T10), which denotes the number of test cases.

For each test case, the first line of input contains single integer n,L,R (2n105,1LR1018).

The second line contains n integers, the i-th integer denotes ai (1ai1018).
 

Output
For each test case, print the number of ways to throw a stick.
 

Sample Input
2 2 1 3 1 1 4 3 10 1 1 2 4
 

Sample Output
2 5
Hint
In the first example, $ 2, 3 $ are available. In the second example, $ 6, 7, 8, 9, 10 $ are available.
 

Source


问题描述
黎明时,Venus为Psyche定下了第二个任务。她要渡过河,收集对岸绵羊身上的金羊毛。

那些绵羊狂野不驯,所以Psyche一直往地上丢树枝来把它们吓走。地上现在有nn根树枝,第ii根树枝的长度是a_ia?i??.

如果她丢的下一根树枝可以和某两根树枝形成三角形,绵羊就会被激怒而袭击她。

现在Psyche手中只有长度不小于LL且不大于RR的树枝。请你帮忙计算,她下一根可以丢多少种不同长度的树枝而不会把绵羊激怒呢?
输入描述
第一行,一个整数T (1 \le T \le 10)T(1T10),代表数据组数。

对于每组数据,第一行有三个整数n,L,Rn,L,R (2 \le n \le 10 ^ 5, 1 \le L \le R \le 10 ^ {18})(2n10?5??,1LR10?18??)。

第二行,nn个整数,第ii个整数为a_ia?i?? (1 \le a_i \le 10 ^ {18})(1a?i??10?18??),代表第ii根树枝的长度。
输出描述
输出TT行,对于每组数据,输出选取方式总数。
输入样例
2
2 1 3
1 1
4 3 10
1 1 2 4
输出样例
2
5
Hint
对于第一组数据,可以选用长度为2, 32,3的树枝。

对于第二组数据,可以选用长度为6, 7, 8, 9, 106,7,8,9,10的树枝。


代码:


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
__int64 L,R,s,shu[100100],mi,ma;
int n;
int main()
{
	int t;scanf("%d",&t);
	while (t--)
	{
		scanf("%d%I64d%I64d",&n,&L,&R);
		for (int i=0;i<n;i++)
		scanf("%I64d",&shu[i]);
		sort(shu,shu+n);
		mi=0;
		ma=R;s=0;
		for (int i=n-1;i>0;i--)
		{
			mi=shu[i]+shu[i-1];
			if (mi<=ma)
			{
				if (mi<=L)
				{
					s+=ma-L+1;
					ma=L-1;
					break;
				}
				else
				s+=ma-mi+1;
			}
			ma=min(ma,shu[i]-shu[i-1]);
			if (ma<L)
			break;
		}
		if (ma>=L)
		s+=ma-L+1;
		printf("%I64d\n",s);
	}
	return 0;
}









BestCoder 2nd Anniversary

标签:

原文地址:http://blog.csdn.net/leibniz_zhang/article/details/51938878

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!