[2018-3-16]BNUZ套题比赛div2 【补题】

比赛的时候不知道在想什么。。。一直懵逼状态,第一题wa了7次才发现看错了题,然后完全不知道为什么要去想数据越界的问题,结果一直卡在那里,到最后都没过,真的智障,然后又跟榜去开了D题,然后算了下发现了尾数规律超过10都为0,其他就是尾数相乘,本来直接相乘然后%10就好的,非要用字符串,然后加加减减,最后也没过,唉,这比赛真的难受,觉得自己真的是不能再懒了,应该更多的精力。

这道题的题意就是有一排可乐,然后给你他的容积和罐里的可乐,问你能不能将所有可乐倒入两个中。

解法就是将最大的两个容器挑出来,然后把所有可乐加起来,如果大于等于就可以分,否则就不可以。

Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai  ≤  bi)


Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!

Input

The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans.

The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans.

The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans.

Output

Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).

You can print each letter in any case (upper or lower).

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[100005];
ll b[100005];
ll c;
ll n,max1,max2,max1_id,max2_id,max3;
int main() {
	while(~scanf("%lld",&n)) {
		max1 = 0;
		c= 0;
		max2 = 0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i= 0; i < n; i++) {
			scanf("%lld",&a[i]);
			c+= a[i];
		}
		for(int i= 0; i < n; i++) {
			scanf("%lld",&b[i]);
		}
		sort(b,b+n);
		max3 = b[n-2] + b[n-1] ;
		if(max3 >= c) {
			printf("YES\n");
		} else {
			printf("NO\n");
		} 
	}
}
这个题的题意就是给你一排人,然后每个人有不同长度的刀,当天黑时,后面的人会用刀杀死刀的长度的人,问最后会有几个活下来。
解法就是从后往前遍历一遍,然后记录每个人的刀长度,途中有更长的刀就更新长度数据,人的位数长于刀长时,这个人就活下来了,然后继续遍历。

Hands that shed innocent blood!

There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.

You are given lengths of the claws. You need to find the total number of alive people after the bell rings.

Input

The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people.

Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.

Output

Print one integer — the total number of alive people after the bell rings.

#include<bits/stdc++.h>
using namespace std;
int num[6666666];
int main() {
	int n;
	while(~scanf("%d",&n)) {
		for(int i = 1; i <= n; i++) {
			scanf("%d",&num[i]);
		}
		int sum = 0;
		int p = n + 1;
		for(int i = n; i >= 1; i--) {
			if(i < p) {
				sum++;
			}
			if( p >= i - num[i]) {
				p = i - num[i];
			}
		}
		printf("%d\n",sum);
	}

}

这个题的题意是求两个数的阶层然后相除,输出最后一位。
解法就是两数大于10的情况下,最后一位一定是0,其余数只要最后一位相乘然后%10就好。
Even if the world is full of counterfeits, I still regard it as wonderful.

Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.

The phoenix has a rather long lifespan, and reincarnates itself once every a! years. Here a! denotes the factorial of integer a, that is, a! = 1 × 2 × ... × a. Specifically, 0! = 1.

Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of b! years, that is, . Note that when b ≥ a this value is always integer.

As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.

Input

The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).

Output

Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.

Example
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
Note

In the first example, the last digit of is 2;

In the second example, the last digit of is 0;

In the third example, the last digit of is 2.

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
	ll a,b;
	while(~scanf("%lld %lld",&a,&b)){
		if(b - a >= 10){
			printf("0\n");
		}
		else{
			ll num = 1;
			for(ll i = a + 1;i <= b;i++){
				num *= i;
				num %= 10;
			}
			printf("%lld\n",num);
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值