【模拟】XMU 1054 Hacker

时间:2023-03-09 03:45:11
【模拟】XMU 1054 Hacker

题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1054

题目大意

  多组数据,n=0结束。给定n(n<=1 000 000)和n个ip(*.*.*.*)求出现次数超过一半的ip是多少(数据保证有)。

题目思路:

  【模拟】

  暴力模拟能A。

  暴力排序能A。

排序:

 //
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 1000004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
struct xxx
{
int s1,s2,s3,s4;
}a[N];
bool cmp(xxx aa,xxx bb)
{
if(aa.s1!=bb.s1)return aa.s1<bb.s1;
if(aa.s2!=bb.s2)return aa.s2<bb.s2;
if(aa.s3!=bb.s3)return aa.s3<bb.s3;
return aa.s4<bb.s4;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n) && n)
{
printf("Case %d:\n",++cas);
for(i=;i<=n;i++)
scanf("%d.%d.%d.%d",&a[i].s1,&a[i].s2,&a[i].s3,&a[i].s4);
sort(a+,a++n,cmp);
printf("%d.%d.%d.%d\n",a[(n+)/].s1,a[(n+)/].s2,a[(n+)/].s3,a[(n+)/].s4);
}
return ;
}
/*
// //
*/

千万不要点

模拟:

 //
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 256
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int u[][N];
int a,b,c,d,aa,bb,cc,dd;
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n) && n)
{
printf("Case %d:\n",++cas);
memset(u,,sizeof(u));
aa=bb=cc=dd=;
for(i=;i<=n;i++)
{
scanf("%d.%d.%d.%d",&a,&b,&c,&d);
u[][a]++;u[][b]++;u[][c]++;u[][d]++;
if(u[][a]>n/)aa=a;
if(u[][b]>n/)bb=b;
if(u[][c]>n/)cc=c;
if(u[][d]>n/)dd=d;
}
printf("%d.%d.%d.%d\n",aa,bb,cc,dd);
}
return ;
}
/*
// //
*/

千万不要点