Codeforces Round #547 (Div. 3)
我老人家走了四公里吃个汉堡还没吃成。垃圾肯德基。垃圾春分半价桶。
蜜雪冰城百香果加冰+烤串真是爽死了。原来二十多块钱可以吃的这么爽。
A:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
if(m%n)cout<<-;
else{
ll tmp = m/n;
int c1=,c2=;
while (tmp%==){
c1++;tmp/=;
}
while (tmp%==){
c2++;tmp/=;
}
if(tmp!=){
cout<<-;
} else{
cout<<c1+c2<<endl;
}
}
}
B:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+;
int n,a[N<<];
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
a[n+i]=a[i];
}
int ans = ,tmp = ;
for(int i=;i<=*n;i++){
if(a[i]==){
tmp++;
} else{
ans = max(ans,tmp);
tmp = ;
}
}
ans = max(ans,tmp);
cout<<ans<<endl;
}
C:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+;
int n,q[N],ans[N];
set<int> s;
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<n;i++){
cin>>q[i];
}
int mx = ;
for(int i=;i<n;i++){
ans[i+]=ans[i]+q[i];
mx = max(mx,ans[i]);
}
mx = max(mx,ans[n]);
for(int i=;i<=n;i++){
ans[i]+=(n-mx);
if(ans[i]>n||ans[i]<){
cout<<-<<endl;
exit();
}
s.insert(ans[i]);
}
if(s.size()!=n) cout<<-;
else{
for(int i=;i<=n;i++){
cout<<ans[i]<<' ';
}
}
}
D:
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
const int N = 15e4+;
int n;
string a,b;
int v1[N],v2[N];
set<int> s[];
vector<pii>ans;
int main(){
ios::sync_with_stdio(false);
cin>>n>>a>>b;a="*"+a;b="*"+b;
for(int i=;i<=n;i++){
if(b[i]=='?')s[].insert(i);
else s[b[i]-'a'].insert(i);
}
for(int i=;i<=n;i++){
if(a[i]=='?')continue;
if(!s[a[i]-'a'].empty()) {
int id = *s[a[i] - 'a'].begin();
ans.push_back(mk(i, id));
s[a[i] - 'a'].erase(id);
v1[i] = ;
v2[id] = ;
} else{
if(s[].empty())continue;
int id = *s[].begin();
ans.push_back(mk(i, id));
s[].erase(id);
v1[i] = ;
v2[id] = ;
}
}
int id = ;
for(int i=;i<=n;i++){
if(a[i]!='?')continue;
while (s[id].empty()){
id++;
if(id>)break;
}
int x = *s[id].begin();
ans.push_back(mk(i,x));
s[id].erase(x);
}
cout<<ans.size()<<endl;
for(auto t:ans){
cout<<t.first<<' '<<t.second<<endl;
} }
E:直接暴力吧。看到同学有写二分的。。。二分个锤子啊。。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+;
ll h, n;
ll a[N],pre[N];
int main(){
ios::sync_with_stdio(false);
cin>>h>>n;
ll tmp = h;
ll mn = 1e18;
for(int i=;i<=n;i++){
cin>>a[i];
tmp+=a[i];
if(tmp<=){
cout<<i;
exit();
}
pre[i]=pre[i-]+a[i];
mn = min(mn,pre[i]);
}
if(pre[n]>=){
cout<<-;
} else{
ll tmp = h+mn;
ll ans = abs(tmp/pre[n]*n);
h-=abs(ans/n*pre[n]);
while () {
for (int i = ; i <= n; i++) {
if (h <= ) {
cout << ans;
exit();
}
h += a[i];
ans++;
}
}
}
}
那么到这里已经过去四十多分钟了,接下来是专治傻逼题。
F2:被治了好几分钟然后挂机睡觉了。
直接暴力枚举所有区间和。完了。
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mk(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
map<int,vector<pii>>mp;
vector<pii>t,v,ans;
bool cmp(pii a,pii b){
return a.second<b.second;
}
int n,a[];
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++){
cin>>a[i];
a[i]+=a[i-];
}
for(int i=;i<=n;i++){
for(int j=i;j<=n;j++){
mp[a[j]-a[i-]].push_back(mk(i,j));
}
}
for(auto x:mp){
t=x.second;
v.clear();
sort(t.begin(),t.end(),cmp);
int tmp = ;
int r=t[].second;
v.push_back(t[]);
for(int i=;i<t.size();i++){
if(t[i].first<=r)continue;
r=t[i].second;tmp++;
v.push_back(t[i]);
}
if(tmp>ans.size()){
ans=v;
}
}
cout<<ans.size()<<endl;
for(auto tmp:ans){
cout<<tmp.first<<' '<<tmp.second<<endl;
}
}
G:我感觉我写的假算法。。和别人的代码,和题解好像都不一样???
首先注意到一个性质,答案其实就是第k+1大的节点度数。
然后我们就搜一遍顺便染个色。
我在搜的过程中 直接把 父节点 能染的颜色起始下标赋给了子节点。。结果1A了。。。不太懂为啥是对的,明天问问学长。。。
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mk(a,b) make_pair(a,b)
using namespace std;
const int N = 2e5+;
struct Node{
int id,deg;
}a[N];
bool cmp(Node a,Node b){ return a.deg>b.deg;}
map<pii,int>mp;
int n,k,deg[N],ans[N],col[N];
vector<int> g[N];
void dfs(int v,int fa,int p){
for(auto u:g[v]){
if(u==fa)continue;
ans[mp[mk(max(u,v),min(u,v))]]=col[v]++;
col[u]=col[v];
col[u]%=p;col[v]%=p;
dfs(u,v,p);
}
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>k;
int u,v;
for(int i=;i<n;i++){
cin>>u>>v;
deg[u]++;deg[v]++;
g[u].push_back(v);
g[v].push_back(u);
mp[mk(max(u,v),min(u,v))]=i;
}
for(int i=;i<=n;i++)a[i]={i,deg[i]},col[i]=;
sort(a+,a++n,cmp);
int tmp = a[k+].deg;
dfs(a[k+].id,a[k+].id,tmp);
cout<<tmp<<endl;
for(int i=;i<n;i++){
cout<<ans[i]+<<' ';
}
}
Codeforces Round #547 (Div. 3)的更多相关文章
- Codeforces Round #547 (Div. 3) 题解
Codeforces Round #547 (Div. 3) 题目链接:https://codeforces.com/contest/1141 A,B咕咕了... C. Polycarp Restor ...
- E. Superhero Battle Codeforces Round #547 (Div. 3) 思维题
E. Superhero Battle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #547 (Div. 3) G 贪心
https://codeforces.com/contest/1141/problem/G 题意 在一棵有n个点的树上给边染色,连在同一个点上的边颜色不能相同,除非舍弃掉这个点,问最少需要多少种颜色来 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
- Codeforces Round #547 (Div. 3) D
http://codeforces.com/contest/1141/problem/D 题目大意: 鞋子匹配,用一个小写字母表示一种颜色.L[i]表示左脚的颜色,R[i]表示右脚的颜色,只有当L[i ...
- Codeforces Round #547 (Div. 3) D. Colored Boots
链接:https://codeforces.com/contest/1141/problem/D 题意: 给连个n长度的字符串. 求两个字符串相同字符对应位置的对数,并挨个打印. 字符:?可以代替任何 ...
- Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest
链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...
- Codeforces Round #547 (Div. 3) A.Game 23
链接:https://codeforces.com/contest/1141/problem/A 题意: 给n和m,有两种操作:将n×2 或 n×3,求最少的乘法次数由n得到m. 不能得到时为-1. ...
- Codeforces Round #547 (Div. 3) E. Superhero Battle
E. Superhero Battle A superhero fights with a monster. The battle consists of rounds, each of which ...
随机推荐
- python 实现简单卷积网络框架
第一步定义卷积核类: class Filter(object): # 滤波器类 对卷积核进行初始化 def __init__(self,width,height,depth): # initializ ...
- 本地图片上传与H5适配知识
最近用到本地图片上传作为API的参数,在网上看了许多,记录一下,以后可能用的着(仅自己记录用,看不清请绕路) function getObjectURL(file) { var url = null ...
- 412 6个题 BOM and DOM 定义计数器 网页跳转 网页前进后退
AM BOM-JavaScript: 提供一系列对象哟用于和浏览器窗口交互,对象主要有 window.document.location.navigator.screen 统称浏览器对象模型(Brow ...
- laravel5.4 导出 Excel 表格
1.执行 composer require maatwebsite/excel 2. composer.json 文件出现(或者手动添加) 3.在config目录下 app.php 添加参数 4.导出 ...
- C语言网蓝桥杯1116 IP判断
判断IP地址的合法性, 1.不能出现除数字和点字符以外的的其他字符 2.数字必须在0-255之间,要注意边界. 题目分析: 因为一个IP是又四个数字组成,且可能存在符号和其他字符,故不能用整型数组处理 ...
- git提交忽略某些文件或文件夹
记得第一次用 github 提交代码,node_modules 目录死活传不上去,哈哈哈,后来才知道在 .gitignore 文件里设置了忽略 node_modules 目录上传.是的, .gitig ...
- 【easy】power of 2,3,4
============================== 2的幂次 ================================ 最佳解法 如果一个数是2的次方数的话,根据上面分析,那么 ...
- ul li 实现层级列表显示
实现效果如下: 实现要求具体如下: 1.标题有序号 上图标记1 2.标题下面的子集标题要有一定的缩进,且子集标题也有一定的序号,上图标记 2 3.如果子集标题内容过长,换行的时,开始的位置不能超过对应 ...
- Mysql -- 数据类型(2)
掌握char类型和varchar类型 掌握枚举类型和集合类型 字符类型 #官网:https://dev.mysql.com/doc/refman/5.7/en/char.html #注意:char和v ...
- Java并发编程的4个同步辅助类
Java并发编程的4个同步辅助类(CountDownLatch.CyclicBarrier.Semphore.Phaser) @https://www.cnblogs.com/lizhangyong/ ...