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的更多相关文章

  1. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

  2. 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 ...

  3. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2)

    A. Be Positive 题意:给出一个数组 每个树去除以d(d!=0)使得数组中大于0的数 大于ceil(n/2) 求任意d 思路:数据小 直接暴力就完事了 #include<bits/s ...

  4. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)C. Morse Code

    题意:给你n个01字符,每次问你前缀的所有本质不同的子串,由摩斯密码组成的方案数和. 题解:离线处理,把字符建sam,通过topo序来dp计算每个节点表示的子串方案数的和.统计答案时,把n个字符挨个匹 ...

  5. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)

    A - Toy Train 很显然,一个站有多少个糖,那么就要从这个点运多少次.设第i个点有\(a_i\)个糖,那么就要转\(a_i-1\)圈,然后再走一段.很显然最后一段越小越好. 然后枚举起点后, ...

  6. 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 ...

  7. Codeforces Round 542 (Div. 2)

    layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  8. Codeforces Round #542 题解

    Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...

  9. int和integer;Math.round(11.5)和Math.round(-11.5)

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

随机推荐

  1. 比较ASP.NET和ASP.NET Core[经典 Asp.Net v和 Asp.Net Core (Asp.Net Core MVC)]

    ASP.NET Core是.与.Net Core FrameWork一起发布的ASP.NET 新版本,最初被称为ASP.NET vNext,有一系列的命名变化,ASP.NET 5.0,ASP.NET ...

  2. 最小的N个和(堆)

    描述: 有两个长度为N的序列 AB,从AB中各选一个数,可以得到N^2个和,求这N^2个和中最小的N个 输入 5 1 3 2 4 5 6 3 4 1 7 输出 2 3 4 4 5 分析: 首先限定输出 ...

  3. Summer sell-off CodeForces - 810B (排序后贪心)

    Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying ...

  4. git的用法步骤讲解

    1.创建全局的本地用户名 git config --global user.name "teamemory" git config --global user.email &quo ...

  5. 解决sqoop连接mysq错误

    一.问题描述 1.由于当前集群没有配置Zookeeper.hcatalog.accumlo,因此应该在sqoop的配置文件中注释掉判断Zookeeper.hcatalog.accumlo路径是否正确的 ...

  6. 简要了解 MySql 5.5/5.6/5.7/8 出现的新特性

    MySQL的开发周期 在比较之前,首先提一下MySQL的开发周期. MySQL一个大版本的开发,大致经历如下几个阶段: Feature Development Feature Testing Perf ...

  7. Prime Permutation

    Prime Permutation 原题地址: http://codeforces.com/problemset/problem/123/A 题目大意: 给你一个字符串(只包含小写字母),从1开始存放 ...

  8. PhpStorm 头部注释、类注释和函数注释的设置

    *设置位置:"Settings"->"file templates"; 如下图,设置头部注释.类注释以及函数注释,时间.用户名.文件名称等随机改变的属性, ...

  9. 源码追踪,解决Could not locate executable null\bin\winutils.exe in the Hadoop binaries.问题

    在windows系统本地运行spark的wordcount程序,会出现一个异常,但不影响现有程序运行. >>提君博客原创  http://www.cnblogs.com/tijun/  & ...

  10. day 7-20 视图,触发器,事务

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...