[NOIP2014D2]
T1
Problem
Solution
枚举那个点的位置,再O(n)扫一遍求出覆盖的公共场合的数量。。。
所以时间复杂度为O(128 * 128 * n)
Code
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int x[25], y[25], val[25];
ll read()
{
ll ans = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
return ans * zf;
}
int main()
{
int d = read(), n = read(), maxnum = 0, maxX = 0;
for (int i = 1; i <= n; i++) x[i] = read(), y[i] = read(), val[i] = read();
for (int xx = 0; xx <= 128; xx++)
for (int yy = 0; yy <= 128; yy++)
{
int num = 0;
for (int i = 1; i <= n; i++)
if (x[i] >= xx - d && x[i] <= xx + d && y[i] >= yy - d && y[i] <= yy + d)
num += val[i];
if (num > maxX)
{
maxX = num;
maxnum = 1;
}
else if (num == maxX) maxnum++;
}
printf("%d %d\n", maxnum, maxX);
}
T2
Problem
Solution
注意读入时连是反向边比较好处理。一下都是按反向边处理的。
先一遍dfs把不能够连到t的点找出来,再把这些点能连到得点也标记掉(也就是原来连着这些点的点)。
最后没被标记的点做一次bfs就好了。
Code
#include<cmath>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
queue <int> q;
ll read()
{
ll ans = 0; int zf = 1; char ch;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') zf = -1, ch = getchar();
while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
return ans * zf;
}
int vet[400005], head[10005], nextx[400005];
int dis[10005], flag[10005], vis[10005];
int num = 0, n, m;
void add(int u, int v)
{
vet[++num] = v;
nextx[num] = head[u];
head[u] = num;
}
void bfs(int s, int t)
{
for (int i = 1; i <= n; i++) dis[i] = 2000000000, vis[i] = 0;
dis[s] = 0;
vis[s] = 1;
q.push(s);
while (!q.empty())
{
int u = q.front();
q.pop();
vis[u] = 0;
for (int i = head[u]; i; i = nextx[i])
{
if (!vis[vet[i]] && flag[vet[i]] == 1)
{
int v = vet[i];
dis[v] = min(dis[v], dis[u] + 1);
q.push(v);
vis[v] = 1;
if (v == t)
{
printf("%d\n", dis[v]);
return;
}
}
}
}
printf("-1\n");
}
void dfs(int u)
{
flag[u] = 1;
for (int i = head[u]; i; i = nextx[i])
if (!flag[vet[i]])
dfs(vet[i]);
}
int main()
{
n = read(), m = read();
for (int i = 1; i <= m; i++)
{
int x = read(), y = read();
add(y, x);
}
int s = read(), t = read();
dfs(t);
for (int i = 1; i <= n; i++)
if (flag[i] == 0)
for (int j = head[i]; j; j = nextx[j])
flag[vet[j]] = -1;
bfs(t, s);
}
[NOIP2014D2]的更多相关文章
随机推荐
- SAP主数据文件版本号命名规范
前提说明 最近在实施公司的SAP系统,需要对供应商,成品半成品原辅料,工艺路线,BOM等各种主数据进行收集,由于牵扯到多个部门进行合作整理数据,为了更方便进行文件版本的管理,特意学习下文件版本号命名规 ...
- Exp2 后门原理与实践 20164303 景圣
Exp2 后门原理与实践 一.基础问题回答: 1.例举你能想到的一个后门进入到你系统中的可能方式? 答:在网上点击不安全的网页或链接. 2.例举你知道的后门如何启动起来(win及linux)的方式? ...
- android架构原理
应用层(与用户打交道) 应用架构层(常用的组件和服务) 系统运行层(Android运行环境+原生c/c++库) Linux核心层(linux内核+硬件抽象层)
- Linux 我的常用命令记录
Linux下复制粘贴快捷键 1. 在终端下: 复制命令:Ctrl + Shift + C 组合键. 粘贴命令:Ctrl + Shift + V 组合键. 2. 在控制台下: 复制命令:Ctrl + ...
- word模板导出的几种方式:第三种:标签替换(DocX组件读取与写入Word)
dll文件下载地址:https://files-cdn.cnblogs.com/files/daizhipeng/DocX.rar DocX wordDocumentOld = DocX.Load(S ...
- mysql基操
创建数据表: create table tt1( id int, name varchar(20), age int,sex boolean ); insert into tt1 values(1,& ...
- AI_群组行为
using System.Collections.Generic; using UnityEngine; public class CrowAI : MonoBehaviour { //当前速度 ; ...
- 论文笔记:Auto-ReID: Searching for a Part-aware ConvNet for Person Re-Identification
Auto-ReID: Searching for a Part-aware ConvNet for Person Re-Identification 2019-03-26 15:27:10 Paper ...
- DLL 破解工具
1.Reflecter+Reflexil (第一类) 2.本文使用的工具下载地址为:(第二类) https://github.com/cnxy/dnSpy/archive/v4.0.0.zip 或 d ...
- Git仓库删除大文件
Git仓库删除大文件 背景 当用Git久了,难免会手误或临时添加一些大文件到仓库中,即使以后添加进了.gitignore,甚至做了git rm,但是Git为了保证版本可回退,history pack里 ...