Educational Codeforces Round 52 (Rated for Div. 2)【A,B,C】【C题:贪心+约束差分模板】

水题。仔细看题

 1 #include<bits/stdc++.h>
 2
 3 using namespace std;
 4 #define int long long
 5 signed main(){
 6     int _;
 7     cin>>_;
 8     while(_--){
 9         int s,a,b,c;
10         cin>>s>>a>>b>>c;
11         int ans=0;
12         ans=(s/(a*c))*a+(s/(a*c))*b+(s%(a*c))/c;
13         cout<<ans<<‘\n‘;
14     }
15
16     return 0;
17 } 

思路:找规律

 1 #include<bits/stdc++.h>
 2
 3 using namespace std;
 4 #define int long long
 5 signed main(){
 6
 7     int n,m;
 8     cin>>n>>m;
 9
10     int ans1=n-min(m*2,n);
11     int ans2=0;
12     for(int i=0;;i++){
13         int cnt=(i-1)*(i)/2;
14         if(cnt>=m){
15             ans2=i;break;
16         }
17     }
18     cout<<ans1<<" "<<n-ans2;
19     return 0;
20 }

思路:约束差分进行O(n)的处理。然后贪心。

 1 #include<bits/stdc++.h>
 2
 3 using namespace std;
 4 #define int long long
 5 #define N 666666
 6 int H[N];int vis[N];//vis数组的定义:高度为I的有VIS[I]个
 7 signed main(){
 8     int n,k;
 9     cin>>n>>k;
10     int maxn=0;
11     for(int i=1;i<=n;i++){
12         scanf("%lld",&H[i]);
13         maxn=max(maxn,H[i]);
14         vis[0]++;
15         vis[H[i]+1]--;
16     }
17     for(int i=1;i<=N;i++){
18         vis[i]+=vis[i-1];
19     }
20     int ans=0;int sum=0;
21 /*    for(int i=1;i<=maxn;i++){//
22         cout<<vis[i]<<" ";
23     }
24     cout<<‘\n‘;
25     */
26     for(int i=maxn;i>=1;i--){
27         if(vis[i]>=n){
28             if(sum)
29                 ans++;
30             break;
31         }
32         if(sum+vis[i]<=k){
33             sum+=vis[i];
34         }else{
35             ans++;
36             sum=vis[i];
37         }
38     }
39     cout<<ans;
40     return 0;
41 }

原文地址:https://www.cnblogs.com/pengge666/p/12186086.html

时间: 2024-07-31 15:28:58

Educational Codeforces Round 52 (Rated for Div. 2)【A,B,C】【C题:贪心+约束差分模板】的相关文章

Educational Codeforces Round 52 (Rated for Div. 2) -C

#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #define ll long long #define rep(i,j,k) for(long long i=j;i<=k;i++) #define per(i,j,k) for(long long i=j;i>=k;i--) using namespace std; const int N =

Educational Codeforces Round 85 (Rated for Div. 2)

Educational Codeforces Round 85 (Rated for Div. 2) A. Level Statistics 签到题, 要求第一位维单增, 第二维变化比第一维慢, 直接模拟即可 B. Middle Class 题目大意 每个人有一些财富, 财富值超过x的人称为富人, 由于实行共产主义, 你可以将某些人的财产重新分配使得富人最多 解题思路 直接按财富值排序, 从大到小加入富人集合, 如果当前富人集合财富平均值小于x就break掉 C. Circle of Monst

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm