本文共 2989 字,大约阅读时间需要 9 分钟。
A
题目大意
为了省去记住价格的麻烦,将所有物品的价格进行统一,然后要我们找出最小的那个价格,使得卖完当前所有物品的价值总和要大于等于原来的价值总和
题解
直接用总和除以物品总数即可,不过我们需要向上取整一下
拓展一下新的取整函数 floor()是向负无穷大舍入,floor(-10.5) == -11; ceil()是向正无穷大舍入,ceil(-10.5) == -10
#includeusing namespace std;int t,n;int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>t; while(t--){ cin>>n; int x; int ans=n-1; for(int i=1;i<=n;i++){ cin>>x; ans+=x; } cout<
#includeusing namespace std;int t,n;int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>t; while(t--){ cin>>n; int x; int ans=0; for(int i=1;i<=n;i++){ cin>>x; ans+=x; } cout<<(int)ceil(ans*1.0/n)<
B
题目大意
由于只是数据范围不同,直接见后面C题解析即可
题解
详情见CCCCCC
C
题目大意
大概讲的是,给你n个消息,然后只有k个格子装,如果格子不存在当前的消息,就把消息放进去,不过要注意格子是有大小的,如果超过大小,就要删除最开始的那条信息,以此类推模拟即可
题解
模拟题,我们可以采用双向队列来做,然后用map维护一下。
我一开始用了一个vis数组来维护的,然后炸掉了,数组范围不够什么的,后面改用map来做就okk了
其实一开始我知道这题双向队列的话会很舒服,但是我想尝试下用map做,然后又考虑map默认key值排序,后面又采用unordered_map尝试了下,发现没有我想象中那么好理解,后面还是老老实实用了双向队列做了
#includeusing namespace std;typedef long long ll;const int maxn=1e8+10;int n,k,x;deque dq;map vis;int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=0;i >x; if(dq.size()
D
题目大意
线段树单点修改区间查询
题解
线段树单点修改区间查询
线段树维护二进制,将查询的字母区间内的字母转化为二进制下,合并区间就是与操作,最后我们看我们所查询得到的二进制有几个1即可
#includeusing namespace std;const int maxn=1e5+10;char s[maxn];int tree[maxn*4];int n,q;inline void PushUp(int rt){ tree[rt]=tree[rt<<1] | tree[rt<<1|1];}void build(int rt,int le,int re){ if(le==re){ tree[rt]=1<<(s[le]-'a'); return; } int mid=(le+re)/2; build(rt<<1,le,mid); build(rt<<1|1,mid+1,re); PushUp(rt);}void Update(int rt,int le,int re,int p,int c){ if(le==re){ tree[rt]=1< re) return 0; if(ql<=le&&qr>=re) return tree[rt]; int mid=(le+re)/2; int res=0; res |=Query(rt<<1,le,mid,ql,qr); res |=Query(rt<<1|1,mid+1,re,ql,qr); return res;}int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>s+1; n=strlen(s+1); build(1,1,n); cin>>q; int op,le,re; char va; while(q--){ cin>>op; if(op==1){ cin>>le>>va; Update(1,1,n,le,va-'a'); } else{ cin>>le>>re; int res=Query(1,1,n,le,re); int cnt=0; while(res){ if(res&1) cnt++; res>>=1; } cout< <
E
题目大意
五个人排队喝可乐,一个人喝完一杯,就在可乐的最后面放两杯自己喝的可乐,问第n个喝的人是谁
题解
#includeusing namespace std;string s[6]={ "0","Sheldon", "Leonard", "Penny", "Rajesh", "Howard" };int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; while(n>5){ n=(n-4)/2; } cout< <
学如逆水行舟,不进则退
转载地址:https://chocolate.blog.csdn.net/article/details/102076224 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!