hdu 5936 Difference 二分
来源:互联网 发布:不要网络的指尖帝国 编辑:程序博客网 时间:2024/06/08 07:34
传送门
题意:挺明显的题意,就是问满足那个等式,有多少y满足。
做法:我学二分的时候在想,左右分一半处理也应该叫二分。这题也就是左右分一半处理,如果我ans[k][i],代表在k的幂次下,i的各个位上的数/sum_{各个位x} x^k。
不管这个数有多大,那么我分一半来算,最后得到的sum肯定是没影响的,那么我左边算一个sum,右边算一个sum。x=sum-i*100000+sum-i,
我把xx2[i]排个序,二分找一下满足sum-i有多少个就好了。统计答案即可,刺激!
/// .-~~~~~~~~~-._ _.-~~~~~~~~~-./// __.' ~. .~ `.__/// .'// \./ \\`./// .'// | \\`./// .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \\`./// .'//.-" `-. | .-' "-.\\`./// .'//______.============-.. \ | / ..-============.______\\`./// .'______________________________\|/______________________________`.#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define s_1(x) scanf("%d",&x)#define s_2(x,y) scanf("%d%d",&x,&y)#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)#define S_1(x) scan_d(x)#define S_2(x,y) scan_d(x),scan_d(y)#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define fOR(n,x,i) for(int i=n;i>=x;i--)#define fOr(n,x,i) for(int i=n;i>x;i--)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db double#define ll long long#define mp make_pair#define pb push_backtypedef long long LL;typedef pair <int, int> ii;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e5+10;const int maxx=4e5+10;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;LL ans1[10][maxn],ans2[10][maxn];LL xx1[maxn],xx2[maxn];LL _pow(LL x,int k){ LL a=1; W(k--) { a*=x; } return a;}void init(){ FOR(1,9,k) { FOr(0,maxn,i) { int cnt=i,t=0; LL ans=0; W(cnt) { int x=cnt%10; ans+=_pow(x,k); cnt/=10; } ans1[k][i]=ans-(LL)i*100000; ans2[k][i]=ans-i; } }}LL check(LL x){ LL xx=upper_bound(xx2,xx2+100000,x)-lower_bound(xx2,xx2+100000,x); return xx;}LL x,k;void solve(){ S_2(x,k); FOR(0,100000,i) { xx1[i]=ans1[k][i]; xx2[i]=ans2[k][i]; } LL cnt=0; if(x==0) cnt--; sort(xx2,xx2+100000); for(int i=0;i<100000;i++) { LL z=x-xx1[i]; cnt+=check(z); } print(cnt);}int main(){ //freopen( "in.txt" , "r" , stdin ); //freopen( "data.txt" , "w" , stdout ); int t=1; init(); s_1(t); for(int cas=1;cas<=t;cas++) { printf("Case #%d: ",cas); solve(); }}
阅读全文
0 0
- hdu 5936 Difference 二分
- Hdu 5936 Difference【思维+折半枚举+二分】
- HDU-5936-Difference(杭州CCPC D题)-二分
- HDU 5936 Difference(思维+二分)——2016年中国大学生程序设计竞赛(杭州)
- HDU 4568 Difference(差分约束 + 二分图)
- HDU 5936 Difference [思维啊]【思维】
- HDU 5936 Difference(折半枚举)
- HDU 5936 Difference 折半枚举,暴力
- hdu 4161 Iterated Difference
- hdu 4598 Difference
- HDU 4598 Difference
- HDU 4161 Iterated Difference
- HDU 5936 && 2016CCPC杭州 D: Difference(折半枚举)
- HDU 4161(Iterated Difference )
- hdu 4715(Difference Between Primes)
- hdu 4715 Difference Between Primes
- hdu 4715Difference Between Primes
- hdu 4715 Difference Between Primes
- spring boot 入门
- hdu 1298 字段树+DFS
- HDU-5924:Mr. Frog’s Problem(不等式变换)
- 图像处理中项目代码合集,包括特征提取-图像分割-分类-匹配-降噪等等
- 部署静态web项目到Tomcat
- hdu 5936 Difference 二分
- 解决AQDefaultDevice (173): skipping input stream 的输出问题
- Groovy入门教程
- Nodejs常用模板引擎
- [BZOJ]2095 二分答案 + 混合图欧拉回路判定
- https请求报错解决: unable to find valid certification path to requested target
- python初步实现word2vec
- [日推荐]『车主码』解决临时停车、请人挪车的小麻烦
- 用windows终端命令删除node_modules用windows终端命令删除文件夹