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 ...
随机推荐
- 无连接运输的UDP、可靠数据传输原理、面向连接运输的TCP
由[RFC 768]定义的UDP只是做了运输协议能够做的最少工作.除了复用/分解功能极少量的差错检测外,它几乎没有对IP增加别的东西.如果应用程序开发人员选择UDP而不是TCP,则该应用程序差不多就是 ...
- Spring基础4
一.Spring的JDBC模板 Spring对持久层也提供了解决方案,ORM模块和JDBC模板 提高简化JDBC或Hibernate的模板 二.JDBC模板使用入门 1)引入jar包:Spring开发 ...
- 第十三章 部署Java应用程序
打包 清单文件被命名为MANIFEST.MF,用于描述归档特征. 清单文件被分为多个节, 第一节被称为主节,作用于整个文件; 其他节则必须起始于Name的条目. 节之间空行分开. jar cfm JA ...
- python中requests的用法
一个最简单的demo: html = requests.get('http://www.cnblogs.com/liaocheng/p/5215225.html') return html.text ...
- Redis学习之二 数据类型和相关命令
原文:https://www.cnblogs.com/lonelyxmas/p/9073928.html 如果还不懂安装的,请看 Windows环境下安装Redis Redis一共支持五种数据类型 1 ...
- MySQL查询表中某个字段的重复数据
1. 查询SQL表中某个字段的重复数据 SELECT user_name,COUNT(*) AS count FROM db_user_info GROUP BY user_name HAVING c ...
- yum [Errno 256] No more mirrors to try 解决方法
[root@localhost yum]# yum update Loaded plugins: fastestmirror, refresh-packagekit, security Reposit ...
- java中的BigDecimal和String的相互转换,int和String的类型转换,Integer类和String相互转换
一: /*由数字字符串构造BigDecimal的方法 *设置BigDecimal的小数位数的方法 */ 注:BigDecimal在数据库中存的是number类型. import java.math.B ...
- MySql新增表的字段,删除表字段
1增加两个字段: create table id_name(id int,name varchar(20));//创建原始数据表 alter table id_name add age int,add ...
- SQL 概述
SQL是用于在数据库中存储,操作和检索数据的标准语言. 本教程教你如何使用SQL:MySQL,SQL Server,MS Access,Oracle,Sybase,Informix,Postgres和 ...