【模拟】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 ;
}
/*
// //
*/
千万不要点
【模拟】XMU 1054 Hacker的更多相关文章
- 【模拟】XMU 1055 数七
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1055 题目大意: 报数游戏,不能报7的倍数和2进制下含有111的数. 给定n,m(1& ...
- 【模拟】XMU 1062 山东煎饼
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1062 题目大意: 已知金钱,和各面额钞票张数,问最少可以换成几张. 题目思路: [模拟 ...
- 【数学】【模拟】XMU 1044 伪伪随机数产生器
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1044 题目大意: 求首项为0,公比为x的等差数列组成的数字条的第y位数字是几.(x,y ...
- 【模拟】XMU 1599 斐波那契汤
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1599 题目大意: 给k,m,q以及f[1]...f[k],当n<m时,f[n]= ...
- XMU 1606 nc与滴水问题 【模拟】
1606: nc与滴水问题 Time Limit: 1000 MS Memory Limit: 64 MBSubmit: 85 Solved: 27[Submit][Status][Web Boa ...
- hacker模拟环境
https://geekprank.com/hacker/
- POJ - 1054 The Troublesome Frog 模拟 枚举优化。
题意:有个R*C的格网.上面有若干个点,这些点可以连成一些直线,满足:这些点在直线上均匀排布(也就是间隔相等),直线的两段穿过网格(也就是第一个,最后一个在网格的边界附近) 求某条直线上最多的点数 题 ...
- The Hacker's Guide To Python 单元测试
The Hacker's Guide To Python 单元测试 基本方式 python中提供了非常简单的单元测试方式,利用nose包中的nosetests命令可以实现简单的批量测试. 安装nose ...
- 【转】lonekight@xmu·ACM/ICPC 回忆录
转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC ...
随机推荐
- IOS 获取wifi的SSID
#import <SystemConfiguration/CaptiveNetwork.h> - (NSString *)currentWifiSSID { // Does not wor ...
- POJ 3449 Geometric Shapes (求正方形的另外两点)
Geometric Shapes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 1470 Accepted: 622 D ...
- jquery之获取当前时间
/** * * 获取当前时间 */ function p(s) { return s < 10 ? '0' + s: s; } var myDate = new Date(); //获取当前年 ...
- JavaBean学习--练习示例
初识Javabean,没感觉这鸟东西有什么好用的,一定是我太笨了 自己用jsp测试了下,这里用application作用域做个示例 <%@ page language="java&qu ...
- css.day03.eg
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 关于异常的疑难解答:System.Runtime.InteropServices.COMException
COMException exception is thrown when an unrecognized HRESULT is returned from a COM method call.&qu ...
- (一)SAPI简述
SAPI,软件中的语音技术包括两方面的内容,一个是语音识别(speech recognition) 和语音合成(speech synthesis).这两个技术都需要语音引擎的支持. 下面我们来了解下基 ...
- sql - 面试
一,关于 group by 表内容: 2005-05-09 胜 2005-05-09 胜 2005-05-09 负 2005-05-09 负 2005-05-10 胜 2005-05-10 负 200 ...
- SQL利用临时表实现动态列、动态添加列
--方法一--------------------------------------------------------------------- declare @sql as varchar(1 ...
- 巧妙的Jq仿QQ游戏导航界面学习
先贴上源代码 <!doctype html> <html> <head> <meta charset="utf-8"> <ti ...