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. Chrome VSCode常用快捷键

    MAC下快捷键 Chrome快捷键: 关闭标签页:Cmd + w 新建标签页:Cmd + t 切换到指定标签页:Cmd + 数字 正向切换标签页: Ctrl + Tab 反向切换标签页: Ctrl + ...

  2. 我应该如何在Pycharm中去运行别人的Django项目

    django数据库迁移,本地运行 前言: 从网络上下载好django项目后,在本地用pycharm导入后,并不能运行.此时我们需要添加库和创建数据库. 零:这里是一个基于django写的小项目,可以作 ...

  3. HTML5滚动加载

    @using YoSoft.DSM.YoDSMModel;@using YoSoft.DSM.YoDSMBLL;@{ Layout = "~/Views/Shared/_LayoutComp ...

  4. 第一次跑eureka

  5. [Redis] - redis实战1

    rememberMe>>>>:null Creating a new SqlSession SqlSession [org.apache.ibatis.session.defa ...

  6. visual studio code——运行python

    How to run Python in Visual Studio Code Getting Started with Python in VS Code python教程 vs code 安装py ...

  7. Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded

    asp.net  更新数据时报错:Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data ...

  8. nrf52832板子焊接后总结的经验

    将之前打的nrf52832的板子拿到手了,经过一番焊接和调试后,发现了一些问题,因为是第一次画板焊接调试,很多地方做的不好,现在将自己的一些经验总结如下: 1 在制板之前,丝印层有必要好好的检查,建议 ...

  9. 【编程语言】Kotlin之object关键字

    在一个体重秤项目里面使用Kotlin开发,考虑到项目比较小型轻量,所以和团队申请决定使用Kotlin开发,以此熟悉和尝试一下Kotlin. 首先使用Kotlin之后,发现能和Java很好的兼容一起,开 ...

  10. k个一组翻转链表(java实现)

    题目: 给出一个链表,每 k 个节点一组进行翻转,并返回翻转后的链表. k 是一个正整数,它的值小于或等于链表的长度.如果节点总数不是 k 的整数倍,那么将最后剩余节点保持原有顺序. 示例 : 给定这 ...