题目传送门 思路 仔细读题后,我们可以发现,输出可以分成\(2\)种情况,apple加s与apple不加s,所以我们可以使用if/else来实现. 接着,我们读入n. int n; cin>>n; 进行判断,是否需要加s if(n==1 || n==0) cout<<"Today, I ate "<<n<<" apple."; else cout<<"Today, I ate "<
题目链接:P5745 [深基附B例]数列求和 现在想说:\(O(N)\)的题要不怎么也想不出来,要不灵光乍现,就像这道题. 我们维护一个类似单调队列的加法单调队列: 若相加大于此数,就将队尾元素弹出,直至满足条件,顺便更新下\(maxn\)值即可. 然后遇见了烦人的头尾双指针,多了个等号就只有\(30\;pts\)了. \(Code\): #include<iostream> #include<cstdio> using namespace std; long long sum=0
题目连接:Harvest of Apples 题意:给出一个n和m,求C(0,n)+C(1,n)+.....+C(m,n).(样例组数为1e5) 题解:首先先把阶乘和逆元预处理出来,这样就可O(1)将C(m,n)求出来了.但这样还是会超时,所以接下来要分块,每隔500个处理出C(1~m,n)的结果.然后还要知道一个性质 C(a,b) = ∑C(t1,x)*C(t2,y) (x+y<=b),这样我们就可以将给出的m和n分为两个组,其中一个组中元素的个数为500的倍数.然后我们对于另一个组枚举可能
Pick apples Time Limit: 1000MS Memory limit: 165536K 题目描写叙述 Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She is so surprised because s
问题 B: Harvest of Apples 时间限制: 1 Sec 内存限制: 128 MB提交: 18 解决: 11[提交] [状态] [讨论版] [命题人:admin] 题目描述 There are n apples on a tree, numbered from 1 to n.Count the number of ways to pick at most m apples. 输入 The first line of the input contains an integer T