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. setInterval中this

    今天使用react做钟表,自然用到了setInterval,但是出现this指向不明的问题. <html> <head> <meta charset="UTF- ...

  2. 细数Linux的文件权限

    普通权限 普通权限使用ls -l查看,最前面显示的即是,如: # ls -l .txt -rw-r--r-- 1 root root 8338 7月 19 20:27 1.txt 权限介绍: -/d/ ...

  3. MySql-2019-4-21-复习

    数据库对象:存储,管理和使用数据的不同结构形式,如:表.视图.存储过程.函数.触发器.事件.索引等. 数据库:存储数据库对象的容器. 数据库分两种: 系统数据库(系统自带的数据库):不能修改 info ...

  4. 自制操作系统Antz(8)——实现内核 (中) 扩展内核

    Antz系统更新地址: https://www.cnblogs.com/LexMoon/category/1262287.html 在前几天的任务中,我们已经简单实现了MBR,直接操作显示器和硬盘操作 ...

  5. 详解docker中容器devicemapper设备的挂载流程

    事故起因 版本说明:本文中docker版本主要基于1.10版本,操作系统为centos7.devicemapper在文中缩写为dm. 某个用户的容器启动不起来,启动时候一直报错.通过docker lo ...

  6. 查看mysql中sql语句执行时间

    查看mysql版本:select version();方法一: show profiles.1. Show profiles是5.0.37之后添加的,要想使用此功能,要确保版本在5.0.37之后.  ...

  7. Educational Codeforces Round 48 (Rated for Div. 2)

    http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原 ...

  8. windows中cmd常用命令收集

    1.经常会启动端口后忘关,需要杀端口的命令:查找端口占用命令 netstat -ano|findstr 端口例如      (8081)      杀端口: taskkill /pid xxxxx - ...

  9. ajax的一些相关

    1.AJAX = Asynchronous(异步的) JavaScript and XML AJAX是能不刷新整个网页的前提下,更新内容.通过少量的数据交换,达成局部页面刷新的效果. 而form表单提 ...

  10. Java利用TCP编程实现简单聊天室

    前言: 本文是我在学习尚学堂JAVA300集第二季网络编程部分仿照视频内容实现而成 具体可以去尚学堂官网观看视频学习 一.实现思路 实现聊天室的最核心部分就是JAVA的TCP网络编程. TCP 传输控 ...