Showstopper

  题目大意:数据挖掘是一项很困难的事情,现在要你在一大堆数据中找出某个数重复奇数次的数(有且仅有一个),而且要你找出重复的次数。

  其实我一开始是没读懂题意的。。。主要是我理解错object的意思了- -

  这一题原理要做出来不难,其实就是二分法,对数二分就好了,因为重复奇数次的数只有一个,所以肯定存在小于等于某一个数时的数的重复次数加起来是奇数,不断二分就可

  关键是是这一题的数据输入超级麻烦,他还会隔行输入。。。。用一行或者多行来区分数据。。。一开始我跳进这个坑里面了。。出题人有意思吗?

  不过还好,让我重新复习了sscanf的用法。。。网上找了个用法比较好的做范例吧。

  

 #include <iostream>
#include <functional>
#include <algorithm>
#include <string.h> typedef long long LL_INT; struct _set
{
LL_INT set_att[];
}refer[]; void Solve(const int, LL_INT);
LL_INT Max(LL_INT, LL_INT);
bool judge(LL_INT, const int);
int Cal_Sum(const int, LL_INT); int main(void)//找出某个数出现的次数为奇数次的数
{
int sum = ;
LL_INT max_num;
char str[]; while (gets(str))
{
sum = ; max_num = -; refer[].set_att[] = ;
sscanf(str, "%lld %lld %lld", &refer[].set_att[], &refer[].set_att[], &refer[].set_att[]);
if (refer[].set_att[] == )
continue;
memset(str, , sizeof(str));
do{
sum++;
gets(str);
if (str[] == ) break;
sscanf(str, "%lld %lld %lld", &refer[sum].set_att[], &refer[sum].set_att[], &refer[sum].set_att[]);
memset(str, , sizeof(str));
max_num = Max(max_num, refer[sum].set_att[]);
} while ();
Solve(sum, max_num);
}
return EXIT_SUCCESS;
} LL_INT Max(LL_INT x, LL_INT y)
{
return x > y ? x : y;
} int Cal_Sum(const int i, LL_INT ans)
{
if (ans<refer[i].set_att[] || ans>refer[i].set_att[])
return ;
else if ((ans - refer[i].set_att[]) % refer[i].set_att[] == )
return ;
else return ;
} void Solve(const int set_sum, LL_INT max_num)
{
LL_INT lb = , ub = max_num, mid, res = ; while (ub - lb > )
{
mid = (lb + ub) >> ;
if (judge(mid, set_sum)) ub = mid;
else lb = mid;
}
for (int i = ; i < set_sum; i++)
res += Cal_Sum(i, ub);
if (res % )
printf("%lld %lld\n", ub, res);
else
printf("no corruption\n");
} bool judge(LL_INT mid, const int set_sum)
{
//只用统计mid(包含mid)的半边就可以了,因为出现奇数次的数只有一个
LL_INT refer_sum = ;
for (int i = ; i < set_sum; i++)
{
if (mid < refer[i].set_att[])//没有任何数出现在左边
continue;
else if (mid > refer[i].set_att[])
refer_sum += (refer[i].set_att[]- refer[i].set_att[]) / refer[i].set_att[] + ;
else
refer_sum += (mid - refer[i].set_att[]) / refer[i].set_att[] + ;
}
return refer_sum % ? : ;
}

  

  参考http://blog.csdn.net/sd_invol/article/details/9410407

    http://blog.csdn.net/u012825876/article/details/27854225

Divide and conquer:Showstopper(POJ 3484)的更多相关文章

  1. Divide and conquer:Sumsets(POJ 2549)

    数集 题目大意:给定一些数的集合,要你求出集合中满足a+b+c=d的最大的d(每个数只能用一次) 这题有两种解法, 第一种就是对分,把a+b的和先求出来,然后再枚举d-c,枚举的时候输入按照降序搜索就 ...

  2. Divide and conquer:Subset(POJ 3977)

    子序列 题目大意:给定一串数字序列,要你从中挑一定个数的数字使这些数字和绝对值最小,求出最小组合数 题目的数字最多35个,一看就是要数字枚举了,但是如果直接枚举,复杂度就是O(2^35)了,显然行不通 ...

  3. Divide and conquer:Garland(POJ 1759)

     挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi ...

  4. Divide and conquer:Matrix(POJ 3685)

    矩阵 题目大意:矩阵里面的元素按i*i + 100000 * i + j*j - 100000 * j + i*j填充(i是行,j是列),求最小的M个数 这一题要用到两次二分,实在是二分法的经典,主要 ...

  5. Divide and conquer:Median(POJ 3579)

        快速求两数距离的中值 题目大意:给你一个很大的数组,要你求两个数之间的距离的中值 二分法常规题,一个pos位就搞定的事情 #include <iostream> #include ...

  6. Divide and conquer:Drying(POJ 3104)

    烘干衣服 题目大意:主人公有一个烘干机,但是一次只能烘干一件衣服,每分钟失水k个单位的水量,自然烘干每分钟失水1个单位的水量(在烘干机不算自然烘干的那一个单位的水量),问你最少需要多长时间烘干衣服? ...

  7. [LeetCode] 236. Lowest Common Ancestor of a Binary Tree_ Medium tag: DFS, Divide and conquer

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  8. [LeetCode] 系统刷题4_Binary Tree & Divide and Conquer

    参考[LeetCode] questions conlusion_InOrder, PreOrder, PostOrder traversal 可以对binary tree进行遍历. 此处说明Divi ...

  9. [LeetCode] 124. Binary Tree Maximum Path Sum_ Hard tag: DFS recursive, Divide and conquer

    Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...

随机推荐

  1. HITtrainning20140417题解

    题目列表:     ID Origin Title 10 / 15 Problem A FZU 2152 文件系统   0 / 16 Problem B FZU 2153 A simple geome ...

  2. mysql sql语句执行时间查询

    第一种:show profiles 之类的语句来查看 1.查一下profile是不是打开了,默认是不打开的. mysql> show profiles; Empty set (0.02 sec) ...

  3. LYDSY模拟赛day3 涂色游戏

    /* 非常好的题 */ #include <cstdio> #include <iostream> #include <cstdlib> #include < ...

  4. PHP的 Mysqli扩展库的多语句执行

    $mysqli->multi_query($sqls);     执行多个sql语句,返回true/false 有结果集时,使用 $mysqli->store_result(); 来获取结 ...

  5. Mac 上真正替换LiveWriter 的工具 - ecto

    Mac 上真正替换LiveWriter 的工具 - ecto 13年开始使用mac.而后想把 windows 替换到.一直在寻找LiveWriter 的工具,至今终于找到 我先感谢这位博主 http: ...

  6. Ubuntu 14 安装 “宋体,微软雅黑,WPS Office的symbol、wingdings、wingdings 2、wingdings 3、webding字体,Consolas雅黑混合版编程字体” 等 Windows 7 下的字体

    Windows平台下,“宋体”.“微软雅黑”.“Courier New(编程字体)”用的比较多,看的也习惯了.那如何在 Ubuntu下也安装这些字体呢? 操作步骤如下: 第一步:从 Windows 7 ...

  7. Chrome Restful Api 测试工具 Postman-REST-Client离线安装包下载,Axure RP Extension for Chrome离线版下载

    [Postman for Chrome 离线下载] Postman-REST-Client离线安装包,可直接在Chrome浏览器本地安装使用,可模拟各种http请求,Restful Api测试, CS ...

  8. DAY2 Python 标准库 -> Getpass 模块 -> 命令行下输入密码的方法.

    getpass 模块 getpass 模块提供了平台无关的在命令行下输入密码的方法. getpass(prompt) 会显示提示字符串, 关闭键盘的屏幕反馈, 然后读取密码. 如果提示参数省略, 那么 ...

  9. RHEL/CentOS 7最小化安装后需做的30件事情

    导读 CentOS是一个工业标准的Linux发行版,是红帽企业版 Linux 的衍生版本.你安装完后马上就可以使用,但是为了更好地使用你的系统,你需要进行一些升级.安装新的软件包.配置特定服务和应用程 ...

  10. iOS使用webView 加载网页,在模拟器中没有问题,而真机却白屏了。App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist f

    还在info.plist中配置.除了配置允许上网的配置之外,还有另一项.