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 (二分+字符串处理)的更多相关文章
- poj3484 Showstopper 二分
题目地址 二分用的很是巧妙!关键是抽象出问题本质. #include <cstdio> #include <string> #include <cstring> ; ...
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...
- COGS 862. 二进制数01串【dp+经典二分+字符串】
862. 二进制数01串 ★ 输入文件:kimbits.in 输出文件:kimbits.out 简单对比 时间限制:1 s 内存限制:128 MB USACO/kimbits(译 by ...
- ACdream 1104 瑶瑶想找回文串(SplayTree + Hash + 二分)
Problem Description 刚学完后缀数组求回文串的瑶瑶(tsyao)想到了另一个问题:如果能够对字符串做一些修改,怎么在每次询问时知道以某个字符为中心的最长回文串长度呢?因为瑶瑶整天只知 ...
- POJ2774 Long Long Message —— 后缀数组 两字符串的最长公共子串
题目链接:https://vjudge.net/problem/POJ-2774 Long Long Message Time Limit: 4000MS Memory Limit: 131072 ...
- HRBUST 1987 逃课的孩子
Sol:HASH + 二分 字符串处理,很基础的操作. 题意很明确就是找重复的次数统计下,范围比较大1≤n≤10000,1≤m≤10000. #include <cstdio> #inc ...
- ACM-ICPC2018南京赛区 Mediocre String Problem
Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...
- P2030 遥控车
P2030 遥控车 2通过 11提交 题目提供者LittleZ 标签二分字符串递推高精洛谷原创 难度尚无评定 提交该题 讨论 题解 记录 最新讨论 暂时没有讨论 题目描述 平平带着韵韵来到了游乐园,看 ...
- [BZOJ4310] 跳蚤 SAM || SA
没有代码的. 传送门 先二分出第 \(mid\) 大的字串 \(s\),然后从后往前切割,每次大于 \(s\) 了就不行. 涉及到的操作:求第 \(mid\) 大子串:比较两个字串(求 \(lcp\) ...
随机推荐
- DEVICE_OBJECT结构参数
typedef struct DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) _DEVICE_OBJECT { CSHORT Type; USHORT Size ...
- wifi钓鱼教程
关于 <原创>想钓鱼必须还要有好竿wifi学习教程+软件下载地址修正 因为最近网盘维护 导致资源无法下载 今天早上开通下载服务了大家可以放心下载. 蹭网要低调不要炫耀 软件介绍:Wires ...
- XAMPP的Apache服务器无法正常启动解决方案
XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建 XAMPP 软件站集成软件包.介绍什么的,参见百度百科http://baike.baidu.com/link?url=-UE ...
- COJ 0999 WZJ的数据结构(负一)
WZJ的数据结构(负一) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 输入N个模板串Pi和文本串T,输出每个模板串Pi在T ...
- 【转】Android开发工具--android-studio-bundle-141.2288178
原文网址:http://www.androiddevtools.cn/ AndroidDevTools简介 Android Dev Tools官网地址:www.androiddevtools.cn 收 ...
- [LeetCode] 128. Longest Consecutive Sequence 解题思路
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- vimrc 留备份
set encoding=UTF-8 "encode with UTF-8"set backspace=2set nusyn onset ai!syntax enablesynta ...
- Hadoop2.4.1 使用MapReduce简单的数据清洗
package com.bank.service; import java.io.IOException;import java.text.ParseException;import java.tex ...
- PHPSTORM实用快捷键
alt + F7 find usages 功能,可以很方便的找到函数在哪里调用了 Ctrl + E 可查看最近打开文件或项目 项目名右键选择"Local History | Show His ...
- Java 实现Md5算法
package other; import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;/* * ...