Line++

Line++

Problem Statement

We have an undirected graph GG with NN vertices numbered 11 to NN and NN edges as follows:

  • For each i=1,2,...,N−1, there is an edge between Vertex i and Vertex i+1.
  • There is an edge between Vertex X and Vertex Y.

For each k=1,2,...,N−1, solve the problem below:

  • Find the number of pairs of integers (i,j)(1≤i<j≤N)such that the shortest distance between Vertex i and Vertex j in G is k.

Constraint

  • \(3≤N≤2×10^3\)
  • \(1≤X,Y≤N\)
  • \(X+1<Y\)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X Y

Output

For each k=1,2,...,N−1 in this order, print a line containing the answer to the problem.

Idea

类似于floyd算法,但是只需要考虑经过x,y时的路程是否更小即可

Code

/******************************************
/@Author: LeafBelief
/@Date: 2020-04-07
/@Remark:    
/@FileName: changeflyord
******************************************/
#include <bits/stdc++.h>
#define CSE(x,y) memset(x,y,sizeof(x))
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn = 2010;
int dis[maxn][maxn], n, x, y;
int ans[maxn];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.in","r",stdin);
    #endif
    FAST;
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            dis[i][j] = dis[j][i] = abs(i -j);
        }
    }
    dis[x][y] = dis[y][x] = 1;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            dis[i][j] = min(dis[i][j], dis[i][x] + dis[y][j] + 1);
        }
    }
    for(int i = 1; i <= n; i++)
        for(int j = i; j <= n; j++)
            ans[dis[i][j]]++;
    for(int i = 1; i < n; i++)
        cout << ans[i] << endl;
    return 0;
}
全部评论

相关推荐

今天 11:18
门头沟学院 Java
作者先叠个甲:本人双非本,秋招拿到了多个大厂offer,这个过程也不容易,但是在看到很多秋招胜利之后说自己一路有多艰辛的文章,总感觉有一点不对劲,想了很久打算写一篇文章分析一下,本文仅代表作者观点,不认同的可以在评论区大家一起理性讨论。&nbsp;秋招已经结束,各类社交平台出现一大批“大厂上岸”胜利结算。文章的叙事逻辑高度相同,开篇就渲染焦虑和困惑,学习时的挑灯夜读、投递时的屡屡碰壁、面试时的如履薄冰,将过往经历包装成一步艰辛的“奋斗史”,然后最终以大厂offer的胜利结尾,字里行间全是苦尽甘来的优越感。但是在我看来,这类文章的本质是结果导向的、带有浮夸的叙事,因为其内核不是分享经验,而是借“苦难”之名...
创作小队长:你的批判视角非常犀利,尤其“结果决定叙事权”的洞察非常精准,哈哈想邀请你来成为我们的创作者🫰 但我想补充一个视角:许多分享者的初衷并非炫耀结果或者苦难,我更愿意相信他们在这个过程中付出了很多,在这场战役结束后,他们迫不及待地想被看到,记录和分享都是给自己的一个交代,而非真的教会别人什么,他们的初衷未必是想制造焦虑。求职市场的残酷、经济环境的下行、世俗价值观才是这种叙事流行的土壤,作为一个普通人无法抵抗洪流。 感谢你发起这场讨论。理想的社区,既需要这样锐利的批判来保持清醒,你的洞察非常犀利,也许会启发一些人,能逐渐改变这种叙事~
点赞 评论 收藏
分享
狸猫换offer:埋点都出来了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务