Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2
A. Be Positive
链接:http://codeforces.com/contest/1130/problem/A
题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后,如果正数的个数可以大于序列长度的一半输出这个d,否则输出0
思路: 直接找正数和负数的个数,正数个数大于一半输出1,负数个数大于一半输出-1,都不大于一半长度输出0就好了
代码:
#include<bits/stdc++.h>
using namespace std; int main()
{
int n,x,a,b;
a = ;b = ;
cin>>n;
for(int i = ;i <= n;i ++){
cin>>x;
if(x>) a++;
else if(x<) b++;
}
if(n%==) n = n/+;
else n = n/;
if(a >= n) cout<<<<endl;
else if(b >= n) cout<<-<<endl;
else cout<<<<endl;
}
B. Two Cakes
链接:http://codeforces.com/contest/1130/problem/B
思路:
每次只有两种取法,每次取局部最优就好了
实现代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 1e5+;
vector<ll>v[M];
int main()
{
ll n,x;
cin>>n;
for(int i = ;i < n*;i ++){
cin>>x;
v[x].push_back(i);
}
ll ans = v[][]+v[][];
for(int i = ;i < n;i ++)
ans += min(abs(v[i][]-v[i+][])+abs(v[i][]-v[i+][]),abs(v[i][]-v[i+][])+abs(v[i][]-v[i+][]));
cout<<ans<<endl;
}
C. Connect
链接:http://codeforces.com/contest/1130/problem/C
题意:给一副地图,0代表陆地,1代表海洋,你只能在陆地上行动,两片陆地之间可以最多建一个通道,通道有花费,问从起点到终点最小的花费是多少
思路:因为图非常小,我们先判断下能否直接从起点到终点,如果不能那么代表起点和终点在两片陆地上,我们分别将两片陆地的所有点存到两个vector里,两重循环枚举一遍所有点,取最小的花费就好了
实现代码:
#include<bits/stdc++.h>
using namespace std;
const int M = ;
const int inf = 0x3f3f3f3f;
int flag,n;
struct node{
int x,y;
};
node s,t;
vector<node>v[];
int vis[M][M];
char mp[M][M];
void dfs(int x,int y,int cnt){
if(x > n||x < ||y > n||y < ) return;
if(vis[x][y]||mp[x][y]=='') return ;
if(x==t.x&&y==t.y&&cnt==) flag = ;
vis[x][y] = ;
node now; now.x = x;now.y = y;
v[cnt].push_back(now);
dfs(x+,y,cnt); dfs(x-,y,cnt); dfs(x,y+,cnt); dfs(x,y-,cnt);
return ;
} int main()
{
cin>>n;
cin>>s.x>>s.y;
cin>>t.x>>t.y;
for(int i = ;i <= n;i ++)
for(int j = ;j <= n;j ++)
cin>>mp[i][j];
dfs(s.x,s.y,);
int mn = inf;
if(flag) cout<<<<endl;
else{
dfs(t.x,t.y,);
for(auto &i: v[]){
for(auto &j: v[]){
mn = min(mn,(i.x-j.x)*(i.x-j.x)+(i.y-j.y)*(i.y-j.y));
}
}
cout<<mn<<endl;
}
}
D2. Toy Train
链接:http://codeforces.com/contest/1130/problem/D2
题意:有从1到n的环状铁道路线,给出m个糖果,每个糖果有信息a,b,代表该糖果在a点要送到b点,问1到n依次为起点的情况下送完所有糖果要走多远
思路:因为要计算的是送完所有糖果需要多远,最优的送法肯定是将离自己最近糖果留到最后,所以我们只需要维护每个点拥有的糖果中需要送的地方离本身点最近的那个糖果,并且维护下每个点有多少颗糖果,因为对于每个点来说一圈才能送掉一颗糖果,最后依次枚举每个起点,看所有点最晚要多久送完,取最久的就好了。
D1和D2是一道题只不过D1的数据小一点,代码两道题都能过。
实现代码;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int M = 6e3;
const int inf = 0x3f3f3f3f;
int n,m,a,b;
int cnt[M],mn[M];
int main()
{
ios::sync_with_stdio();
cin.tie(); cout.tie();
int mx = ,maxx= ;
cin>>n>>m;
memset(mn,inf,sizeof(mn));
for(int i = ;i <= m;i ++){
cin>>a>>b;
if(b < a) b += n;
if(b - a < mn[a]) mn[a] = b-a;
cnt[a]++;
}
for(int i = ;i <= n;i ++){
maxx = ;
for(int j = ;j <= n;j ++){
if(cnt[j]){
if(j < i) maxx = max(maxx,j+n-i+mn[j]+(cnt[j]-)*n);
else maxx = max(maxx,j-i+mn[j]+(cnt[j]-)*n);
}
}
cout<<maxx<<endl;
}
return ;
}
Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2的更多相关文章
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解
Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)
http://codeforces.com/contest/1129/problem/C #include<bits/stdc++.h> #define fi first #define ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2)
A. Be Positive 题意:给出一个数组 每个树去除以d(d!=0)使得数组中大于0的数 大于ceil(n/2) 求任意d 思路:数据小 直接暴力就完事了 #include<bits/s ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)C. Morse Code
题意:给你n个01字符,每次问你前缀的所有本质不同的子串,由摩斯密码组成的方案数和. 题解:离线处理,把字符建sam,通过topo序来dp计算每个节点表示的子串方案数的和.统计答案时,把n个字符挨个匹 ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)
A - Toy Train 很显然,一个站有多少个糖,那么就要从这个点运多少次.设第i个点有\(a_i\)个糖,那么就要转\(a_i-1\)圈,然后再走一段.很显然最后一段越小越好. 然后枚举起点后, ...
- Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) 题解
A. Toy Train 时间限制:2 seconds 内存限制:256 megabytes 题意 有编号111~n(n≤5000)n(n\le 5000)n(n≤5000)的车站顺时针呈环排列,有m ...
- Codeforces Round 542 (Div. 2)
layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #542 题解
Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...
- int和integer;Math.round(11.5)和Math.round(-11.5)
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...
随机推荐
- 2019年DNS服务器速度排行榜
第一名:DNSPod 不得不说腾讯自从收购了DNSPod后,无论是服务还是速度都有显著的提升,无论是访问速度还是解析速度都在国内是处于龙头大哥的地位,昔日的老大114的地位已经不保,作为腾讯旗下的公司 ...
- H5 16-并集选择器
16-并集选择器 我是标题 我是段落 我是段落 我是段落 <!DOCTYPE html> <html lang="en"> <head> < ...
- hdu3790 dijkstra+堆优化
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=3790 分析:dijkstra没有优化的话,复杂度是n*n,优化后的复杂度是m*logm,n是顶点数,m ...
- 使用 Travis CI 实现项目的持续测试反馈
[篇幅较长,10.15前补充完毕,如希望探索可直接移步Github仓库:https://github.com/SivilTaram/CITest] 在编程课中,我们可以使用成熟的在线评测系统来测试某个 ...
- scrapy之五大核心组件
scrapy之五大核心组件 scrapy一共有五大核心组件,分别为引擎.下载器.调度器.spider(爬虫文件).管道. 爬虫文件的作用: a. 解析数据 b. 发请求 调度器: a. 队列 队列是一 ...
- hangfire使用笔记
1.导入nuget包 2.配置 简单配置后就可以写自己的Job了 注意:Hangfire.RecurringJobExtensions这个扩展支持两种job添加方法:json配置文件和特性.但由于时区 ...
- hive权限配置
基于CDH5.x的Hive权限配置 1.打开权限控制,默认是没有限制的 set hive.security.authorization.enabled=true; 2.配置默认权限 hive.secu ...
- hive条件过滤
where 过滤 %代表任意个字符,_代表一个字符; \\ 转移字符.\\_代表下划线
- python学习笔记(7)--循环语句
循环语句如下: for i in range(start, end): //注意 前闭后开 coding for i in range(m,n,k): coding for c in s: codin ...
- bash中的pasue
#!/bin/bash echo 按任意键继续 read -n