朋友

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/The_most_handsome/article/details/77099641

题目描述

经过六年的努力,小明终于被一所知名中学录取。优秀的小明总是对一些奇奇怪怪的事情感兴趣,这次他想知道谁在这所新学校拥有的朋友最多,由于大家都才刚报到,所以小明只知道大家两两之间是否是朋友关系。

输入

输入文件friend.in的第一行有两个整数n和m,n表示总人数,m表示总关系数。
接下来n行,每行有2个以空格隔开的整数a和b,表示a和b是朋友,a和b均为1到n之间的整数。不会给出重复的朋友关系。

输出

输出文件friend.out中仅有一行,表示朋友数最多的人所拥有的朋友,每两个整数之间用空格隔开,按照字典序从小到大输出。如果存在多个人朋友数都是最多的情况,请输出字典序最小的那人的答案,具体见样例。

样例输入

3 3
1 2
2 3
1 3

样例输出

2 3

数据范围限制

50%的数据,1 <= n <= 10
80%的数据,1 <= n <= 1000
100%的数据,1 <= n <= 10000,m <= 500000

提示

1、2、3均拥有2个朋友,因此输出字典序较小的1的朋友即可。
1的朋友为2和3,按照字典序从小到大输出,数字之间用空格隔开。

TJ

直接暴力……

BC

var
        n,m,i,x,y:longint;
        p:array[1..10000,1..10000]of boolean;
        nl:array[1..10000,1..2]of int64;
procedure kp(l,r:longint);
var
        i,j,mid,mid1:longint;
        t:array[1..2]of int64;
begin
        i:=l;
        j:=r;
        mid:=nl[(l+r)div 2,2];
        mid1:=nl[(l+r)div 2,1];
        repeat
                while (nl[i,2]>mid)or(nl[i,2]=mid)and(nl[i,1]<mid1) do inc(i);
                while (nl[j,2]<mid)or(nl[j,2]=mid)and(nl[j,1]>mid1) do dec(j);
                if i<=j then
                begin
                        t:=nl[i];
                        nl[i]:=nl[j];
                        nl[j]:=t;
                        inc(i);
                        dec(j);
                end;
        until i>j;
        if l<j then kp(l,j);
        if i<r then kp(i,r);
end;
begin
        assign(input,'friend.in');reset(input);
        assign(output,'friend.out');rewrite(output);
        readln(n,m);
        for i:=1 to m do
        begin
                readln(x,y);
                p[x,y]:=true;
                p[y,x]:=true;
                inc(nl[x,2]);
                inc(nl[y,2]);
        end;
        for i:=1 to n do nl[i,1]:=i;
        kp(1,n);
        for i:=1 to n do if p[nl[1,1],i] then write(i,' ');
        writeln;
        close(input);close(output);
end.
展开阅读全文

朋友帮帮忙

11-30

AccountNumber SessionID SiteID ChannelID SectionID PageID HitDate Browser OS IPAddressrnPA10010 1456-3245-455678 1011 2022 3510 456 10/10/2009 10:00 AM IE7 Vista 192.168.1.46rnPA10010 1456-3245-455678 1011 2022 0 456 10/10/2009 10:02 AM,IE7,Vista,192.168.1.46rnPA10011 1456-3245-455678 1011 2022 3510 0 10/10/2009 10:00 AM,IE7,Vista,192.168.1.46rnPA10011 1456-3245-455678 1011 2022 0 587 10/10/2009 10:02 AM,IE7,Vista,192.168.1.46rnPA10011 1456-3245-455678 1011 0 0 123 10/10/2009 10:05 AM,IE7,Vista,192.168.1.46rnPA10011 1456-3245-455678 1011 1345 0 123 10/10/2009 10:10 AM,IE7,Vista,192.168.1.46rnrn结果[color=#FF0000]: AN为AccountNumber下面写不下了[/color]rnAN StartDate TotalSessionMinutes TotalSessions TotalUniqueVisits TotalVisits TotalUniqueViews TotalViews rnPA10010 10/10/2009 2 2 2 2 (统计PageID)??? 2rnPA10011 10/10/2009 10 4 4 4 (统计PageID)??? 2rnrn现在想实现 按AccountNumber,HitDate(只按日期)分组插入另一表中。问题在这里 想统计出 每个分[color=#FF0000]组内PageID大于0 并且有相同的只要算一次[/color] 请教朋友们我应该怎么做,下面是我写的程序。PageID这个部份没有统计出来。请指教rnrnrnALTER PROCEDURE dbo.SessionHitsCrunchrnAS BEGIN rnSET NOCOUNT ONrnrnBEGIN TRANrn rn BEGIN TRY rn rn -- Create table @Trn rn DECLARE @T TABLErn (rn AccountNumber NVARCHAR(20) NULL,rn StatDate VARCHAR(10) NULL,rn SessionID NVARCHAR(30) NULL,rn DomainID INT NULL,rn PageFlag INT NULL,rn PageID INT NULL,rn HitDate DATETIME NULL,rn Browser NVARCHAR(200) NULL,rn OS NVARCHAR(20) NULL,rn IPAddress NVARCHAR(15) NULLrn )rn rn -- Add data to @Trn rn INSERT INTO @T(rn [AccountNumber],rn [StatDate],rn [SessionID],rn [DomainID],rn [PageFlag],rn [PageID],rn [HitDate],rn [Browser],rn [OS],rn [IPAddress] rn )rn SELECT rn [AccountNumber],rn CONVERT(NVARCHAR(10),HitDate,120) AS StatDate,rn [SessionID],rn (CASE WHEN SectionID <> 0 THEN SectionID WHEN ChannelID <> 0 THEN ChannelID WHEN SiteID <> 0 THEN SiteID END) AS DomainID, rn (CASE WHEN PageID = 0 THEN 0 ELSE 1 END) AS PageFlag,rn [PageID],rn [HitDate],rn [Browser],rn [OS],rn [IPAddress]rn FROM SessionHitsrn rn -- View @Trn rn SELECT * FROM @T rn rn -- Count data for AccountStats table.rn rn INSERT INTO AccountStatsrn (rn [AccountNumber],rn [StatDate],rn [TotalSessionMinutes],rn [TotalSessions],rn [TotaluniqueVisits],rn [TotalVisits],rn [TotalUniqueViews],rn [TotalViews] rn )rn SELECT rn [AccountNumber],rn CONVERT(DATETIME,StatDate,120),rn DATEDIFF(MINUTE,MIN(HitDate),MAX(HitDate)) TotalSessionMinutes,rn COUNT(SessionID) As TotalSessions,rn COUNT(DomainID) AS TotalUniqueVisits,rn COUNT(AccountNumber) AS TotalVisits,rn COUNT(DISTINCT PageID) AS TotalUniqueViews,rn --SUM(PageFlag) AS TotalUniqueViews,rn COUNT(PageID) AS TotalViewsrn FROM @T rn GROUP BY AccountNumber,StatDatern rn COMMIT TRANrn RETURN 0rn END TRYrn rn BEGIN CATCHrn DECLARE @ErrMsg NVARCHAR(4000), @ErrSeverity INTrn SELECT @ErrMsg = ERROR_MESSAGE(),@ErrSeverity = ERROR_SEVERITY()rn RAISERROR(@ErrMsg, @ErrSeverity, 1) rn ROLLBACK TRAN rn RETURN -1rn END CATCH rn rnENDrnrnrnrnrnrn帮忙求出 TotalUniqueViews 或者给个思想 或者在原程序上修改,谢谢rn 论坛

没有更多推荐了,返回首页