Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most k pebbles in each pocket at the same time. There are n different pebble types in the park, and there are wi pebbles of the i-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
3 2
2 3 4
3
5 4
3 1 8 9 7
5
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type.
- In the second day she collects 8 pebbles of the fourth type.
- In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type.
- In the fourth day she collects 7 pebbles of the fifth type.
- In the fifth day she collects 1 pebble of the second type.
题意:n个东西 每次有两个容量为k的容器 给你n个东西的大小 问你需要装几次可以装走所有的物品 每次同一个容器中只能放置一种东西
题解:水
1 #include<bits/stdc++.h> 2 using namespace std; 3 int n,k; 4 int exm; 5 int main() 6 { 7 scanf("%d %d",&n,&k); 8 int ans=0; 9 for(int i=1;i<=n;i++) 10 { 11 scanf("%d",&exm); 12 ans=ans+exm/k; 13 if(exm%k) 14 ans++; 15 } 16 int re=0; 17 re=ans/2; 18 if(ans%2) 19 re++; 20 printf("%d ",re); 21 return 0; 22 }
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = bi - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a1, a2, ..., am, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |bi| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a1, a2, ..., am (-109 ≤ ai ≤ 109) — numbers that will never be written on the board.
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
3 2 30 4
6 14 25 48
3
123 1 2143435 4
123 11 -5453 141245
0
123 1 2143435 4
54343 -13 6 124
inf
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
题意:给你一个等比数列的初项 公比 数字的上界 现在写出满足的项 有m个不能出现的数字 问能写出多少项
题解:暴力
1 #include<bits/stdc++.h> 2 #define ll __int64 3 using namespace std; 4 ll b1,q,l,m; 5 ll exm; 6 map<ll,int>mp; 7 ll ans=0; 8 int main() 9 { 10 scanf("%I64d %I64d %I64d %I64d",&b1,&q,&l,&m); 11 for(ll i=1;i<=m;i++) 12 { 13 scanf("%I64d",&exm); 14 mp[exm]=1; 15 } 16 for(int i=1;i<=1000;i++) 17 ans=0; 18 for(int i=0;i<501;i++) 19 { 20 if(abs(b1)>l) break; 21 if(mp[b1]!=1) ans++; 22 b1*=q; 23 } 24 if(ans>100) 25 printf("inf "); 26 else 27 printf("%I64d ",ans); 28 return 0; 29 }
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:
In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.
The first line contains single integer n (2 ≤ n ≤ 105) — the size of the array a.
The second line contains n integers a1, a2, ..., an (-109 ≤ ai ≤ 109) — the array elements.
Print the only integer — the maximum value of f.
5
1 4 2 3 1
3
4
1 5 4 7
6
In the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of f is reachable only on the whole array.
题意: 给你一个长度为n的数列 对于这个数列输出最大的f(l,r)
题解:处理出每一项绝对值 求两遍最大子序列和
1 #include<bits/stdc++.h> 2 #define ll __int64 3 using namespace std; 4 int n; 5 ll a[100005]; 6 ll b[100005]; 7 ll c[100005]; 8 int main() 9 { 10 scanf("%d",&n); 11 for(int i=1; i<=n; i++) 12 scanf("%I64d",&a[i]); 13 ll exm=0; 14 for(int i=1; i<n; i++) 15 { 16 exm=a[i]-a[i+1]; 17 if(exm<0) 18 exm=-exm; 19 if(i%2==1) 20 { 21 b[i]=exm; 22 c[i]=-exm; 23 } 24 else 25 { 26 b[i]=-exm; 27 c[i]=exm; 28 } 29 } 30 ll sum=0; 31 ll maxn1=-1e15,maxn2=-1e15; 32 for(int i=1; i<n; i++) 33 { 34 sum+=b[i]; 35 if(sum>maxn1) 36 { 37 maxn1=sum; 38 } 39 else if(sum<0) 40 { 41 sum=0; 42 if(i%2==1) 43 i--; 44 } 45 } 46 sum=0; 47 for(int i=2; i<n; i++) 48 { 49 sum+=c[i]; 50 if(sum>maxn2) 51 { 52 maxn2=sum; 53 } 54 else if(sum<0) 55 { 56 sum=0; 57 if(i%2==0) 58 i--; 59 } 60 } 61 cout<<max(maxn1,maxn2)<<endl; 62 return 0; 63 }