比赛的时候不知道在想什么。。。一直懵逼状态,第一题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!
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.
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.
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.
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就好。
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.
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
2 4
2
0 10
0
107 109
2
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);
}
}
}