cf B Inna and Candy Boxes

题意:输入n,然后输入n个数ai,再输入n个数bi,如果在1-ai中能找到两个数x,y,x和y可以相等,如果x+y=bi,答案加上x*y,否则减去1,让结果尽可能大,输出结果。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define ll long long
 5 #define maxn 100100
 6 using namespace std;
 7
 8 int n;
 9 ll a[maxn],b[maxn];
10
11 int main()
12 {
13     while(scanf("%d",&n)!=EOF)
14     {
15         memset(a,0,sizeof(a));
16         memset(b,0,sizeof(b));
17         for(int i=1; i<=n; i++)
18         {
19             scanf("%lld",&a[i]);
20         }
21         for(int i=1; i<=n; i++)
22         {
23             scanf("%lld",&b[i]);
24         }
25         ll ans=0;
26         for(int i=1; i<=n; i++)
27         {
28             if(b[i]==1)
29             {
30                 ans--;
31                 continue;
32             }
33             if(b[i]-a[i]>a[i])
34             {
35                 ans--;
36                 continue;
37             }
38             if(b[i]%2==0)
39                 ans+=(ll)((ll)(b[i]/2)*(ll)(b[i]/2));
40             else
41                 ans+=(ll)((ll)(b[i]/2)*(ll)(b[i]/2+1));
42         }
43         printf("%lld\n",ans);
44     }
45     return 0;
46 }

时间: 2024-11-05 06:27:09

cf B Inna and Candy Boxes的相关文章

cf C. Inna and Candy Boxes

题意:给你一个长度为n的只含有1和0的字符串,w个询问,每次询问输入l,r:在[l,r]中在l+k-1.l+2*k-1.......r的位置都必须为1,如果不为1的,变成1,记为一次操作,其它的地方的都必须为0,不为0的地方要变成1,也记为一次操作,最后问在区间[l,r]最少几次操作. 思路:可以用树状数组记录在某个地方的右方有多少个1,然后在 预处理出从1,2,..k的为开头的在i+c*k-1的位置上前面有多少个1,最后的答案是拿走的1+添加的1,拿走的1的个数等于现有的1的个数-位置正确的1

Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]

哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058                 2014-11-22 06:52:58     njczy2010     B - Candy Boxes             GNU C++     Accepted 31 ms 4 KB 8795016                 2014-11-22 06:48:15     njczy2010     B - Candy Boxes             GNU C+

CF488 B.Candy Boxes

数学+暴力 1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include<queue> 7 #include<algorithm> 8 #include<map> 9 #include<iomanip> 10 #include<climi

dp题目列表

10271 - Chopsticks 10739 - String to Palindrome 10453 - Make Palindrome 10401 - Injured Queen Problem 825 - Walking on the Safe Side 10617 - Again Palindrome 10201 - Adventures in Moving - Part IV 11258 - String Partition 10564 - Paths through the Ho

hdu 4465 Candy (快速排列组合 )

Candy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2115    Accepted Submission(s): 910 Special Judge Problem Description LazyChild is a lazy child who likes candy very much. Despite being ve

HDU 4465 Candy

Candy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2520    Accepted Submission(s): 1100Special Judge Problem DescriptionLazyChild is a lazy child who likes candy very much. Despite being very

Candy( 数学期望 )

Candy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1830    Accepted Submission(s): 794 Special Judge Problem Description LazyChild is a lazy child who likes candy very much. Despite being ve

HDU 4465 Candy(组合+log优化)

题目大意:给你两个罐子,里面有糖果每次只能从一个罐子里面取一个糖果,打开A的概率为p,问当一个罐子取完之后,另一个罐子剩糖果的期望是多少. 我们可以知道最少是取第n+1次的时候才会有一个罐子为空,我们可以推出组合公式: (n-k)*C(n+k, k)*((1-p)^(n+1)*p^k+(1-p)^k*p^(n+k)):0 <= k && k <= n-1. 求一个和就是所有的组合情况了,但是组合数很大我们可以用log来进行优化. 我们已知:C(n,m) = m!/n!/(m-n

uva 1639--精度处理方法之取对数对数(uva 1639)

1639 - Candy Time limit: 3.000 seconds 1639 CandyLazyChild is a lazy child who likes candy very much. Despite being very young, he has two large candy boxes, each contains n candies initially. Everyday he chooses one box and open it. He chooses the ?