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. 误删除(重命名)libc.so.6的处理方法

    LD_PRELOAD=/lib64/libc-2.12.so ln -s /lib64/libc-2.12.so /lib64/libc.so.6 ssh尚未断开的话可以直接这样操作,断开之后可以用l ...

  2. python:循环定义、赋值多个变量

    exec函数,可以循环定义.赋值多个变量 exec ("temp%s=1"%1)   这段代码的意思是,让exec执行temp1=1.字符串里面的%s由‘1’代替了. 我们在外面再 ...

  3. Oracle 12c 单实例安装

    准备工作 实验环境:Redhat 6.6   Oracle 12c 12.2.0.1 1.官网下载 https://www.oracle.com/technetwork/database/enterp ...

  4. vs2013突然打不开项目,项目全部不兼容

    转载:https://forum.cocos.com/t/vs2013/40931 转载:https://jingyan.baidu.com/article/cdddd41c7c6b5353cb00e ...

  5. Hadoop3.2.0集群(4节点-无HA)

    1.准备环境 1.1配置dns # cat /etc/hosts 172.27.133.60 hadoop-01 172.27.133.61 hadoop-02 172.27.133.62 hadoo ...

  6. 举例理解JDK动态代理

    JDK动态代理 说到java自带的动态代理api,肯定离不开反射.JDK的Proxy类实现动态代理最核心的方法: public static Object newProxyInstance(Class ...

  7. kafka 创建消费者报错 consumer zookeeper is not a recognized option

    在做kafka测试的时候,使用命令bin/kafka-console-consumer.sh --zookeeper 192.168.0.140:2181,192.168.0.141:2181 --t ...

  8. python中一个汉字点3个字节? utf-8

    今天发现了一个汉字占了3个字节,一开始以为是两个呢,字符串切片时总出现乱码,后来才发现一个中文占3个字节.这才解决了乱码问题 原来  1. utf-8 编码中,一个汉字占三个字节.英文字母是一个占用一 ...

  9. js的原型/原型链/构造函数

    js里一切皆对象.有js自己内部的对象,还有用户自定义的对象.所有的对象都是从原型上衍生出来的. 原型本身也是对象,原型链的最高层就是Object. 两个重要的属性:prototype, __prot ...

  10. expect简单自动交互-用于密码、命令输入

    1. 安装expect #yum -y install expect 2. 新建.exp文件,用于ssh交换机 #vi exp.exp #!/bin/expect set f [open ipfile ...