Educational Codeforces Round 96 (Rated for Div. 2)
今天先补了上一场的Codeforces Global Round 11三道题,做的心神恍惚,然后17点报名没敢提交,先写了4个题剩下的改天补一补
我是真的服信号,卷积卷si我了
A - Number of Apartments
枚举3和5的个数,直接算出来7的个数即可
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=100010;
int main()
{IO;int T=1;cin>>T;while(T--){int n;cin>>n;bool ok=0;for(int i=0;i<=n;i++){if(ok) break;for(int j=0;j<=n;j++){int k=n-3*i-5*j;if(k<0||k%7) continue;cout<<i<<' '<<j<<' '<<k/7<<'\n';ok=1;break;}}if(!ok) cout<<-1<<'\n'; }return 0;}
B - Barrels
很明显需要把第2~k+1大的全部导入最大的容器中,然后求个和即是答案
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int n,k;
int a[N];
int main()
{IO;int T=1;cin>>T;while(T--){cin>>n>>k;for(int i=1;i<=n;i++) cin>>a[i];sort(a+1,a+1+n);reverse(a+1,a+1+n);ll res=0;for(int i=1;i<=k;i++) res+=a[i+1];res+=a[1];cout<<res<<'\n';}return 0;}
C - Numbers on Whiteboard
贪心:1一定最后再用,然后依次用两个最大的即可。
总的来说就是每次用两个最大的。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int n,k;
int a[N];
int main()
{IO;int T=1;cin>>T;while(T--){cin>>n;vector<pii> ans;int now=n;for(int i=1;i<n;i++){ans.push_back({n-i,now});now=(n-i+now+1)/2;}cout<<now<<'\n';for(auto t:ans) cout<<t.first<<' '<<t.second<<'\n';cout<<'\n';}return 0;}
D - String Deletion
首先扫一遍序列,把相同的分段用一个vector存下来,不难发现我如果当前的一段个数大于1我们只需要两次操作都在这一段即可,否则只需要在后面的段中选择一个个数大于1的用操作1即可,简单模拟。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
int n,k;
char s[N];
int main()
{IO;int T=1;cin>>T;while(T--){cin>>n;cin>>s+1;vector<int> now;for(int i=1;i<=n;i++){int j=i+1;while(j<=n&&s[i]==s[j]) j++;now.push_back(j-i);i=j-1;}int res=0;for(int i=0,j=0;i<now.size();i++){if(now[i]>=2){res++;continue;}bool ok=0;j=max(j,i+1);for(;j<now.size();j++){if(now[j]>=2) {now[j]--;ok=1;break;}}if(!ok) i++;res++;}cout<<res<<'\n';}return 0;
}
E - String Reversal
不难贪心出结论即:每次选择离自己最近的字母交换
首先可以记下每个字母出现的位置用26个vector即可,用树状数组快速求出每次移动需要的代价然后就不难得出答案了。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=200010;
char s[N],p[N];
int n;
queue<int> mp[27];
int tree[N];
int lowbit(int x)
{return x&-x;
}
void update(int k,int x)
{for(;k<=n;k+=lowbit(k)) tree[k]+=x;
}
int query(int k)
{int res=0;for(;k;k-=lowbit(k)) res+=tree[k];return res;
}
int main()
{IO;int T=1;//cin>>T;while(T--){cin>>n;cin>>s+1;for(int i=1;i<=n;i++){mp[s[i]-'a'].push(i);update(i,1);}ll res=0;for(int i=n;i;i--)//逆序字符{int pos=mp[s[i]-'a'].front();mp[s[i]-'a'].pop();res+=query(pos)-1;update(pos,-1);}cout<<res<<'\n';}return 0;}
我是刚刚做完信号的一题来写的题解,现在心态非常爆炸。。。
题解质量不想说了真的laji
剩下的题明天补一下吧(明天信号又要自己看书了,老师讲的根本听不懂啊啊啊)
要加哟哦~~
Educational Codeforces Round 96 (Rated for Div. 2)相关推荐
- C. Numbers on Whiteboard(模拟+贪心) Educational Codeforces Round 96 (Rated for Div. 2)
原题链接: https://codeforces.com/contest/1430/problem/C 测试样例 input 1 4 output 2 2 4 3 3 3 1 题意: 给定一个 1 1 ...
- Educational Codeforces Round 96 (Rated for Div. 2) C. Numbers on Whiteboard///思维
cf地址 题目大意:给一个数n,有1~n的数,每次现在两个数a,b,将这两个数去掉,然后添加一个(a+b)/2的数(向上取整),进行n-1次操作后,问你最后剩下的数最小是多少. 思路:最小的数必定为2 ...
- Educational Codeforces Round 96 (Rated for Div. 2) ABCD
很久不写题解了 因为最近一直在刷acwing和kuangbin的专题 acwing题解直接在acwing上传了 而kuangbin做了几个半个专题 完整了会写题解的 因为身体原因最近总是眼睛疼所以很少 ...
- Educational Codeforces Round 96 (Rated for Div. 2) C. Numbers on Whiteboard(构造)
C. Numbers on Whiteboard 题意: 给你一个排列1-n,每次可以选择两个数,( ⌈ a + b 2 ⌉ \lceil \frac{a+b}{2} \rceil ⌈2a+b⌉)进 ...
- Educational Codeforces Round 96 (Rated for Div. 2)C. Numbers on Whiteboard(贪心算法(水题))
题目链接: 传送门 题目贴上: 题意:,给你 1-n个数,你可以对两个不同位置的数进行合并,比如a和b,合成数变成(a+b)/2,结果四舍五入.放在数组末尾,删除原来的a和b,举例子吧 就这样子两两合 ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
最新文章
- 用Python对数学函数进行求值、求偏导
- OFFICE——Word与Excel交互处理——邮件合并
- java将html实体字符转换成正常字符
- 光绘文件 c语言 解析,AltiumDesigner输出光绘文件
- ad采样做按键开关_电池应用中的电流采样电阻设计
- 昨夜,拼多多发布财报后,大家只看到了用户达到7.31亿
- java 多线程 最优_Java多线程与并发系列从0到1全部合集,强烈建议收藏!
- shiro 同时实现url和按钮的拦截_Shiro权限管理框架(一):Shiro的基本使用
- 关于python 输出中文
- 易语言自定义数据类型转c,转换JSON结构为易语言代码自定义数据类型
- sort函数和sorted函数的异同
- i.MX6ULL系统移植 | 移植NXP官方linux4.1.15内核
- Banner(轮播)
- 【图像去噪】基于柯西近端分裂 (CPS) 算法实现图像去噪附MATLAB源代码
- 虚拟化技术之KVM,搭建KVM(详细)
- FileReader和FileWrite介绍
- 秒懂设计模式之组合模式(Composite Pattern)
- BZOJ3032 七夕祭 均分纸牌问题的变式 (前缀和+中位数)
- 倍增算法入门 超详细解答+LCA+RMQ(ST表)+例题剖析
- 点云综述一稿 点云硬件、点云软件、点云处理算法、点云应用以及点云的挑战与展望
热门文章
- 无源的nfc加传感_基于ON Semiconductor SPS无源温度标签,应用于冷链运输的 UHF 标签读取器方案...
- 利用计算机制作多媒体最后一步,福建省高中会考 多媒体技术应用 选择题专项练习十一(201206)(有答案)...
- 顺丰gis产品经理_线上面试季丰图科技—顺丰旗下专注GIS领域
- 计算机二级链表,计算机二级c语言上机考试——结构体与链表(3页)-原创力文档...
- node.js require 自动执行脚本 并生成html,nodejs 执行脚本并实时输出
- linux网卡驱动 pdf,Linux下网卡驱动程序.pdf
- 幂等问题 vs 如何判断是否是4的幂
- [MyBatisPlus]入门案例
- [SpringBoot2]拦截器
- 算法-排序-归并排序