码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #619 (Div. 2)C(构造,容斥)

时间:2020-02-15 18:58:38      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:sync   int   space   time   个数   while   family   ros   code   

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int main(){
 5     ios::sync_with_stdio(false);
 6     cin.tie(NULL);
 7     cout.tie(NULL);
 8     int t;
 9     cin>>t;
10     while(t--){
11         long long n,m;
12         cin>>n>>m;
13         long long ans=0;
14         ans=(n*(n+1))>>1;//总方案数(无论当中是否存在1)
15         long long temp=n-m;//0的个数
16         long long x=temp/(1+m);//将0均分(猜测这样答案最大)
17         long long y=temp%(1+m);//有y段会多余1个0,长度为x+1
18         long long z=1+m-y;//长度为x的段数
19         ans-=z*((x+1)*x/2)+y*((x+1)*(x+2)/2);//总方案数减去中间全是0的字串数量
20         cout<<ans<<"\n";
21     }
22     return 0;
23 }

 

Codeforces Round #619 (Div. 2)C(构造,容斥)

标签:sync   int   space   time   个数   while   family   ros   code   

原文地址:https://www.cnblogs.com/ldudxy/p/12312950.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!