HDU 5478 Can you find it (2015年上海赛区网络赛K题)
2015-09-26 19:30
429 查看
1.题目描述:点击打开链接
2.解题思路:本题利用枚举法+随机数解决。通过分析可以发现,一个a只对应一个b,因此不妨枚举a,在n=1时候求出相应的b,接下来只需要在[1,C)范围内用随机数检测等式是否恒成立即可。通过尝试发现,用随机数测试500次即可。
3.代码:
2.解题思路:本题利用枚举法+随机数解决。通过分析可以发现,一个a只对应一个b,因此不妨枚举a,在n=1时候求出相应的b,接下来只需要在[1,C)范围内用随机数检测等式是否恒成立即可。通过尝试发现,用随机数测试500次即可。
3.代码:
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<algorithm> #include<cassert> #include<string> #include<sstream> #include<set> #include<bitset> #include<vector> #include<stack> #include<map> #include<queue> #include<deque> #include<cstdlib> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<cctype> #include<complex> #include<functional> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; #define me(s) memset(s,0,sizeof(s)) #define rep(i,n) for(int i=0;i<(n);i++) typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair <ll,ll> P; const int N = 200000 + 10; int C; ll k1, b1, k2; vector<P>ans; ll pow_mod(ll a, ll n, int M) { ll res = 1; while (n>0) { if (n & 1)res = res*a%M; a = a*a%M; n >>= 1; } return res; } bool check(ll a, ll b) { for (int j = 0; j < 500;j++) { int i = rand() % C + 1; ll r1 = (k1*i + b1) % (C - 1); ll r2 = (k2*i - k2 + 1) % (C - 1); ll t1 = pow_mod(a, r1, C); ll t2 = pow_mod(b, r2, C); if ((t1 + t2) % C)return false; } return true; } int main() { int rnd = 0; srand(time(NULL)); while (~scanf("%d%d%d%d", &C, &k1, &b1, &k2)) { printf("Case #%d:\n", ++rnd); ans.clear(); for (int a = 1; a<C; a++) { ll tmp = pow_mod(a, k1 + b1, C); ll b = C - tmp; if (check(a, b))ans.push_back(P(a, b)); } if (ans.empty())puts("-1"); else { sort(ans.begin(), ans.end()); int len = ans.size(); for (int i = 0; i<len; i++) printf("%lld %lld\n", ans[i].first, ans[i].second); } } }
相关文章推荐
- 【中秋佳节】简易爬虫的探讨
- hdu 5475 An easy problem 2015上海网络赛 模拟 剪枝
- iOS开发 ----- 网络请求3 ----- 上传数据
- iOS开发 ----- 网络请求4 ----- 下载数据以及断点续传
- iOS开发 ----- 网络请求2 ----- 请求数据
- iOS开发 ----- 网络请求1 ----- 概览
- Android网络编程之搭建一个属于你自己的简单servlet服务端。
- Web压力测试工具:http_load、webbench、ab、Siege使用方法
- Swift - 异步获取网络数据封装类
- JavaSE--- 网络编程
- 2015上海网络赛 HDU 5478 Can you find it 数学
- 2015上海网络赛 HDU 5475 An easy problem 线段树
- 2015 上海网络赛
- Samba网络文件共享服务介绍
- 第2章 TCP/IP基础知识
- 5中服务器的网络编程
- c++调用winhttp对象
- iOS中一种网络层与业务层的设计方案
- Linux网络虚拟化与MLPPP多链路
- 2015亚洲网络赛上海站1010A Sweet Journey