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

随机推荐

  1. 给COCO数据集的json标签换行

    #include <iostream> #include <fstream> #include <string> #include <vector> u ...

  2. 如何加速GitHub访问速度

    http://tool.chinaz.com/网站中填入assets-cdn.github.com选取响应最小的ip,将ip.域名填入到C:\Windows\System32\drivers\etc下 ...

  3. 关于html中的 script标签中的 代码写法有效性? easyui tabs的href不能载入内容页面

    script标签, 即 html中的 js脚本区域中: 它其实就是一个 普通的 html标签, 在 html 渲染器 parser 看来, 它跟其他任何的普通 的 html标签 , 比如 p 标签, ...

  4. Tag

    C# ASP.NET SQL SERVER .Net Entity Framework JS Question Records Others

  5. 我的第一篇博客。(JavaScript的声明和数据类型的一些笔记)

    这是我的第一篇博客,务必请大家多多关照. 下面是前端js的变量和数据类型的一些笔记,不是很全请多多包涵. 1.变量 变量的声明 var 变量名 变量这个容器中放的是数据 变量的赋值 变量名 = 数据 ...

  6. IT项目管理十大要素

    1.项目需求PgMp.mypm.net 当项目混乱和不可控的时候,往往是源头出了问题,解决源头才能治本.项目管理者联盟文章 软件项目中的范围管理重点就是项目需求,需求包括原始需求,用户需求,产品需求和 ...

  7. C# 批量新增的两种方法。

    public class Test { private static readonly string strConnection = ""; public static void ...

  8. oracle to_char 格式大全

    Postgres 格式化函数提供一套有效的工具用于把各种数据类型(日期/时间,int,float,numeric)转换成格式化的字符串以及反过来从格式化的字符串转换成原始的数据类型. 注意:所有格式化 ...

  9. 使用Keepalived配置主从热备实现Nginx高可用(HA)

    Keepalived 简要介绍 Keepalived 是一种高性能的服务器高可用或热备解决方案,Keepalived 可以用来防止服务器单点故障的发生,通过配合 Nginx 可以实现 web 前端服务 ...

  10. Xilinx Vivado的使用详细介绍(4):Zedboard+vivado之流水灯(加SDK)

    Vivado+zedboard之初学流水灯 Author:zhangxianhe 环境:vivado 2016.3(已验证适用于2015.4) 开发板:Zedboard version xc7z020 ...