题目链接:

  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 ;
}
/*
// //
*/

千万不要点

最新文章

  1. 享元模式/Flyweight模式/对象结构型/设计模式
  2. webapi版本升级管理
  3. MySQL的学习--用户创建授权
  4. HBase的RowKey设计原则
  5. React Native 开发。
  6. 【Convert Sorted List to Binary Search Tree】cpp
  7. *[hackerrank]Algorithmic Crush
  8. Hadoop datanode无法启动的错误
  9. log4j2j配置
  10. Balls Rearrangement(HDU)
  11. 自己动手做聊天机器人 二十九-重磅:近1GB的三千万聊天语料供出
  12. 201521123065《Java程序设计》第2周学习总结
  13. Spring IOC容器分析(2) -- BeanDefinition
  14. Python xml处理模块
  15. Python爬虫之Selenium库的基本使用
  16. LeetCode算法题-Design HashMap(Java实现)
  17. 023_supervisorctl管理服务注意事项
  18. Linux 下执行本目录的可执行文件(命令)为什么需要在文件名前加“./”
  19. VS2017离线安装入门与出家
  20. RabbitMQ 设置消息的TTL(过期时间)

热门文章

  1. CSU1661: Query Mutiple
  2. Swift: 继承
  3. linux的文本管道连接处理技巧
  4. 【教训】rm -fr ./* 教训
  5. NYOJ 1107 最高的奖励(贪心+优先队列)
  6. ASP.NET数据报表之柱状图 ------工作日志
  7. Dedecms调用文章发布时间的方法
  8. Android比较实用的属性
  9. ASP.NET5 静态文件
  10. app发布流程详解