POJ3484 Showstopper

  题目大意:

  每次给出三个数x,y,z,用这三个数构成一个等差数列,x为首项,y是末项,z是公差

  总共给出n组x,y,z( n待定),求这n组数列中出现次数为奇数的那个数以及该数出现的次数(保证最多有一个数出现的次数为奇数)

  首先就是字符串的处理,以及求出n

  

  一直没怎么接触过字符串,一开始根本不知道怎么读入数据,在看了大牛的代码后,知道了sscanf()这个函数神奇的用法,数据读入基本就是copy大牛的代码过来的,

  对于最后数据的判断还是不太清楚,不加最后的判断就会wa,还有就是所有的数据最好都用long long,

  二分基本上是用的自己的模板,对于这种类型的整数二分,现在写二分终于不再像几天前一样老是出现死循环了

  本题二分枚举的mid是出现次数为奇数的数,

  采用方法的是对前缀和出现的总次数相加,小于正确值的数都出现偶数次,则当枚举的值小于正确值时,前缀和相加为偶数,

  当枚举的值大于等于正确值时,前缀和相加为奇数,sum&1时,ub=mid即可,最后C(ub)-C(ub-1)即可得到mid出现的次数;

  

/*
* Created: 2016年04月03日 20时06分30秒 星期日
* Author: Akrusher
*
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define in(n) scanf("%d",&(n))
#define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
#define in3(x1,x2,x3) scanf("%d%d%d",&(x1),&(x2),&(x3))
#define inll(n) scanf("%I64d",&(n))
#define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
#define inlld(n) scanf("%lld",&(n))
#define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
#define inf(n) scanf("%f",&(n))
#define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
#define inlf(n) scanf("%lf",&(n))
#define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
#define inc(str) scanf("%c",&(str))
#define ins(str) scanf("%s",(str))
#define out(x) printf("%d\n",(x))
#define out2(x1,x2) printf("%d %d\n",(x1),(x2))
#define outf(x) printf("%f\n",(x))
#define outlf(x) printf("%lf\n",(x))
#define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
#define outll(x) printf("%I64d\n",(x))
#define outlld(x) printf("%lld\n",(x))
#define outc(str) printf("%c\n",(str))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(X,Y) memset(X,Y,sizeof(X));
typedef vector<int> vec;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={,,-,},dy[]={,,,-};
const ll INF=1ll<<; //直接用1移位会爆int
const ll mod=1e9+;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
const bool AC=true; const int M_case=+;
ll x[M_case],y[M_case],z[M_case];//等差数列,x为首项,y是末项,z是公差
ll cnt;
char str[];
//偶偶偶偶偶偶奇(mid)奇奇奇奇奇
ll C(ll mid){ //返回值用ll,否则会wa
ll sum=,temp;
rep(i,,cnt){
if(mid<x[i]) continue;
temp=min(mid,y[i])-x[i];
sum+=temp/z[i]+; //前缀和出现的次数,包括当前
}
return sum ; //奇数为true;
}
void solve(){
ll lb,mid,ub;
lb=1ll,ub=INF;
while(ub>lb){
mid=(lb+ub)>>;
if(C(mid)&) ub=mid;
else lb=mid+;
}
if(lb==INF) printf("no corruption\n");
else printf("%lld %lld\n",ub,C(ub)-C(ub-));//计算次数
}
int main()
{
cnt=;
while(gets(str)!=NULL){
if(strlen(str)==){
if(cnt==) continue; //注意输入数据之间可能又多行空格
solve();
cnt=;
}
else{
sscanf(str,"%I64d%I64d%I64d",&x[cnt],&y[cnt],&z[cnt]);
cnt++;
}
}
if(cnt)
solve();//必须加上判断,否则会wa
return ;
}

POJ3484 Showstopper (二分+字符串处理)的更多相关文章

  1. poj3484 Showstopper 二分

    题目地址 二分用的很是巧妙!关键是抽象出问题本质. #include <cstdio> #include <string> #include <cstring> ; ...

  2. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

  3. COGS 862. 二进制数01串【dp+经典二分+字符串】

    862. 二进制数01串 ★   输入文件:kimbits.in   输出文件:kimbits.out   简单对比 时间限制:1 s   内存限制:128 MB USACO/kimbits(译 by ...

  4. ACdream 1104 瑶瑶想找回文串(SplayTree + Hash + 二分)

    Problem Description 刚学完后缀数组求回文串的瑶瑶(tsyao)想到了另一个问题:如果能够对字符串做一些修改,怎么在每次询问时知道以某个字符为中心的最长回文串长度呢?因为瑶瑶整天只知 ...

  5. POJ2774 Long Long Message —— 后缀数组 两字符串的最长公共子串

    题目链接:https://vjudge.net/problem/POJ-2774 Long Long Message Time Limit: 4000MS   Memory Limit: 131072 ...

  6. HRBUST 1987 逃课的孩子

    Sol:HASH + 二分  字符串处理,很基础的操作. 题意很明确就是找重复的次数统计下,范围比较大1≤n≤10000,1≤m≤10000. #include <cstdio> #inc ...

  7. ACM-ICPC2018南京赛区 Mediocre String Problem

    Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...

  8. P2030 遥控车

    P2030 遥控车 2通过 11提交 题目提供者LittleZ 标签二分字符串递推高精洛谷原创 难度尚无评定 提交该题 讨论 题解 记录 最新讨论 暂时没有讨论 题目描述 平平带着韵韵来到了游乐园,看 ...

  9. [BZOJ4310] 跳蚤 SAM || SA

    没有代码的. 传送门 先二分出第 \(mid\) 大的字串 \(s\),然后从后往前切割,每次大于 \(s\) 了就不行. 涉及到的操作:求第 \(mid\) 大子串:比较两个字串(求 \(lcp\) ...

随机推荐

  1. 【行为型】Chain of responsibility模式

    职责链模式将对象的请求处理组成链式结构,并将请求按链式结构逐个传递下去,直接被其中的某个处理者处理为止.由此可知,职责链模式的适用场合是对指定请求,可以有多个请求处理者(或称为请求响应者),但用户并不 ...

  2. JavaScript常用

    打印日志 console.log 类型判断 第一种方式var type = Object.prototype.toString.call(list);console.log(type);第二种方式ty ...

  3. ioctl函数,可以获取ip地址,修改ip地址,网卡地址等

    部分转自http://www.cnblogs.com/zht-blog/p/4025903.html #include <sys/types.h>#include <sys/sock ...

  4. iOS开发之UIWebView自动滑动到顶部-备

    但可以通过subview来操作. 通常用UIWebView加载网页,有时候需要点击一个按钮,或者页面的某个部位,使页面自动滚动到顶部,但是UIWebView不像UIScrollView那么方便.   ...

  5. 『软件介绍』SQLServer2008 基本操作

    0x 01 连接数据库 Win7下,先打开SQLServer管理工具(开始菜单/所有程序/Microsoft SQL Server 2008/SQL Server Management Studio) ...

  6. 转:Raspberry Pi(树莓派)试用小记

    近期入手一树莓派卡片机,体验了一下它的强大,写篇报告,推广一下哈! 机器截图: 基础参数: CPU:700 MHz, ARM11 内存:512M(还有一种是256M的) 支持GPU加速(高清视频无压力 ...

  7. 测试Beetle.Redis+Web Api

    在Web Api里用Beetle.Redis调用Redis服务端的TIME命令返回一个json格式,然后客户端是用的HttpTest4Net做的测试: CPU:I7-3770 内存:4G+4G 硬盘: ...

  8. WebService实现文件上传下载

    一:服务端:一个普通java web工程 package com.wzh.file; import com.sun.xml.ws.developer.StreamingAttachment; impo ...

  9. 转: Python 运算符与用法

    +加两个对象相加 3 + 5得到8.'a' + 'b'得到'ab'. (注意:6+'a'这样是错误的,但在PHP里这样是可以运行的) -减得到负数或是一个数减去另一个数 -5.2得到一个负数.50 - ...

  10. linux开源论坛

    开源资源: 开源http://oss.org.cn/?action-news http://www.lupaworld.com/proj.php http://www.10pig.cn/linux/o ...