2019dx#7
| Solved | Pro.ID | Title | Ratio(Accepted / Submitted) |
![]() |
1001 | A + B = C | 10.48%(301/2872) |
| 1002 | Bracket Sequences on Tree | 11.27%(16/142) | |
| 1003 | Cuber Occurrence | 6.67%(1/15) | |
| 1004 | Data Structure Problem | 23.08%(3/13) | |
| 1005 | Equation | 0.00%(0/63) | |
![]() |
1006 | Final Exam 推公式,田忌赛马 | 5.06%(297/5872) |
| 1007 | Getting Your Money Back | 12.42%(20/161) | |
![]() ![]() |
1008 | Halt Hater | 14.77%(61/413) |
| 1009 | Intersection of Prisms | 0.00%(0/2) | |
![]() |
1010 | Just Repeat 博弈,贪心 | 15.04%(128/851) |
![]() |
1011 | Kejin Player 期望DP | 21.20%(544/2566) |
1001 A + B = C
题意:
给定a,b,c($a, b, c \le 10 ^{100000}$),求一组x, y, z满足$a \times 10^x + b \times 10^y = c \times 10^z$ 。
思路:
先把每个数末尾的0去掉,然后可以发现满足如下等式之一$$ a + b = c \times 10 ^k $$ $$ a \times 10 ^k + b = c $$ $$ a + b \times 10 ^ k = c$$就行了。
由于是大数,可以利用哈希,计算等式中的k,可以移项,乘逆元,预处理mod意义下指数。
然后我用到双哈希保险
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
#include <unordered_map>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/**********showtime************/
const int maxn = 1e5+;
const int N = 1e5+;
char a[maxn],b[maxn],c[maxn];
char d[maxn];
int mod1 = , mod2 = 1e9+;
int ten1[N], ten2[N];
unordered_map<int,int>mp1,mp2;
void init(){
ten1[] = ten2[] = ;
mp1[] = mp2[] = ;
for(int i=; i<N; i++)
{
ten1[i] = 1ll*ten1[i-] * % mod1;
ten2[i] = 1ll*ten2[i-] * % mod2; mp1[ten1[i]] = i;
mp2[ten2[i]] = i;
}
}
ll ksm(ll a, ll b, ll mod){
ll res = ;
while(b > ) {
if(b & ) res = res * a % mod;
a = a * a % mod;
b = b >> ;
}
return res;
}
int main(){
init();
// debug("ok");
int T; scanf("%d", &T); while(T--) {
scanf("%s%s%s", a, b, c);
int alen = strlen(a), blen = strlen(b), clen = strlen(c);
int cnta = , cntb = , cntc = ;
while(a[alen-] == '') alen--, cnta ++;
while(b[blen-] == '') blen--, cntb ++;
while(c[clen-] == '') clen--, cntc ++;
int kk = max(cnta, max(cntb, cntc));
a[alen] = '\0';
b[blen] = '\0';
c[clen] = '\0';
ll A1 = , B1 = , C1 = ;
ll A2 = , B2 = , C2 = ; for(int i=; i<alen; i++){
A1 = (A1 * + (a[i] - '') ) % mod1;
A2 = (A2 * + (a[i] - '') ) % mod2;
} for(int i=; i<blen; i++){
B1 = (B1 * + (b[i] - '') ) % mod1;
B2 = (B2 * + (b[i] - '') ) % mod2;
} for(int i=; i<clen; i++){
C1 = (C1 * + (c[i] - '') ) % mod1;
C2 = (C2 * + (c[i] - '') ) % mod2;
} int k1 = (A1 + B1) % mod1 * ksm(C1, mod1-, mod1) % mod1;
if(mp1.count(k1))k1 = mp1[k1];
else k1 = -;
int k2 = (A2 + B2) % mod2 * ksm(C2, mod2-, mod2) % mod2;
if(mp2.count(k2))k2 = mp2[k2];
else k2 = -;
if(k1 == k2 && k1 >= ) {
printf("%d %d %d\n", kk - cnta, kk - cntb, kk + k1 - cntc);
continue;
} k1 = (C1 - B1) % mod1;
if(k1 < ) k1 += mod1;
k1 = k1 * ksm(A1, mod1-, mod1) % mod1;
if(mp1.count(k1))k1 = mp1[k1];
else k1 = -; k2 = (C2 - B2) % mod2;
if(k2 < ) k2 += mod2;
k2 = k2 * ksm(A2, mod2-, mod2) % mod2;
if(mp2.count(k2))k2 = mp2[k2];
else k2 = -;
if(k1 == k2 && k1 >= ) {
printf("%d %d %d\n", kk + k1 - cnta, kk - cntb, kk - cntc);
continue;
} k1 = (C1 - A1) % mod1;
if(k1 < ) k1 += mod1;
k1 = k1 * ksm(B1, mod1-, mod1) % mod1;
if(mp1.count(k1))k1 = mp1[k1];
else k1 = -; k2 = (C2 - A2) % mod2;
if(k2 < ) k2 += mod2;
k2 = k2 * ksm(B2, mod2-, mod2) % mod2;
if(mp2.count(k2))k2 = mp2[k2];
else k2 = -;
if(k1 == k2 && k1 >= ) {
printf("%d %d %d\n", kk - cnta, kk + k1 - cntb, kk - cntc);
continue;
}
puts("-1");
}
return ;
}
1006 Final Exam
思路:
假设每个题目所用的时间为$a_1, a_2, ... , a_n(a_i <= a_{i+1})$
按老师的想法,为了不让学生过掉n - k 个题目,肯定是把$a_1, a_2,...a_{n-k}$ 对应题目的分值设为$a_1, a_2,...a_{n-k}$.
然后$$m - a_1 - a_2 - ... - a_{n-k} < a_{n-k+1}$$
我们给左边+1,再移项,变成
$$m + 1 \le + a_1 + a_2 + ... + a_{n-k} + a_{n-k+1}$$
可以发现$a_{n-k+1}$最大会被老师卡成$\left\lceil \frac{m + 1}{n - k + 1} \right\rceil$
之后的$a_{n-k+2},,,a_{n}$可以等于$a_{n-k+1}$就行了。
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/**********showtime************/ int main(){
int T; scanf("%d", &T);
while(T--) {
ll n, m , k;
scanf("%lld%lld%lld", &n, &m, &k);
ll tmp = (m + ) / (n - k + );
if((m+) % (n - k + )) tmp++;
ll ans = (k - ) * tmp + m+ ;
printf("%lld\n", ans);
} return ;
}
1008 Halt Hater
题意:
一开始你在(0, 0)点,面向Y轴正方向。向左走费用为a,向前走费用为b,向右走费用为0。有T($\le 100000$) 组数据,每组给定x,y,a,b,问你到(x,y)的最小费用。
思路:
规律题,首先发现,你到(x-1, y+1)(x, y+1), (x-1, y), (x, y) 其中之一就行了。
然后发现,如果把每个格子看成一个点,那么,相邻格子的费用为a。斜对着的两个格子的费用为min(a, 2 * b)。
一下跨两步的费用为min(2*a, 2*b)。
所以我们首先斜着走,然后两步两步走,然后再走一步。
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize(4)
#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
#include <unordered_map>
// #include<bits/extc++.h>
// using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a) typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = ; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
/**********showtime************/ ll a, b, x, y;
ll check(ll x, ll y) { x = abs(x), y = abs(y); ll ans = ;
ll m = min(x, y); ans += m * min(a, 2ll * b);
ll yu = x + y - m - m;
ans += (yu / ) * min(2ll * a , 2ll * b); if(yu % == ) ans += b;
return ans;
}
int main(){
int T; scanf("%d", &T);
while(T--) {
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
ll ans = check(x, y);
ans = min(ans, check(x-, y));
ans = min(ans, check(x, y+));
ans = min(ans, check(x-, y+));
printf("%lld\n", ans);
}
return ;
}
2019dx#7的更多相关文章
- 2019DX#10
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Minimum Spanning Trees 22.22%(2/9) 1002 Lin ...
- 2019dx#9
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Rikka with Quicksort 25.85%(38/147) 1002 Ri ...
- 2019DX#8
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Acesrc and Cube Hypernet 7.32%(3/41) 1002 A ...
- 2019DX#6
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Salty Fish 16.28%(7/43) OK 1002 Nonsense Tim ...
- 2019DX#5
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 fraction 辗转相除 4.17%(7/168) ok 1002 three arr ...
- 2019dx#4
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 AND Minimum Spanning Tree 31.75%(1018/3206) ...
- 2019DX#3
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Azshara's deep sea 凸包 6.67%(6/90)
- 2019DX#2
Solved Pro.ID Title Ratio(Accepted / Submitted) 1001 Another Chess Problem 8.33%(1/12) 1002 Beau ...
- 2019DX#1
1001 Blank 题意 有一个长度为n(n<=100)的位子,填入四种颜色,有m个限制,某个区间的颜色个数要恰好等于x个.问颜色个数的方案数. 思路 DP 四维的DP,利用滚动数组优化一维空 ...
随机推荐
- 华为路由交换综合实验 ---IA阶段
目录 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 华为路由交换综合实验 ---IA阶段 实验拓扑 实验需求 根据拓扑合理规划IP地址以及VLANIf地址(PC1属于运营部,PC2属于市场 ...
- Android 开发环境之 VMware 虚拟机(android8.1)
VM版本14 在官网下载androidx86的VMDK文件 官方下载地址 (VMDK文件是VMware的专用文件,比iso镜像文件安装要简便许多,内部已经配置好了,只需要按照虚拟机安装普通流程即可) ...
- Guitar Pro如何更改五线谱的符杆方向
可能有的小伙伴不知道Guitar Pro是什么软件,我先稍微给大家介绍一下~ Guitar Pro是专为帮助所有吉他爱好者学习.绘谱.创作的多功能软件.它包含所有吉他的现有指法和音色,可以帮助我们了解 ...
- JDK的命令行工具系列 (三) jhat、jstack
jhat: heapdump文件分析工具 在前两篇系列文章JDK的命令行工具系列 (一) jps.jstat.JDK的命令行工具系列 (二) javap.jinfo.jmap中, 我们已经介绍过了jp ...
- 在Java大环境下.NET程序员如何夺得一线生机
先来看一组数据,从某招聘网站直接检索3-4w的岗位,会看到Java与.NET社会需求量的巨大差异,这里就不再对比高薪的岗位了,.NET的高薪岗位更是少的可怜: 笔者从业十余年,一直是在.NET圈子 ...
- Oracle jdbc 插入 clob blob
Oracle 使用 clob 与 blob 插入一些比较庞大的文本或者文件,JDBC 插入时 也比较简单 表结构 CREATE TABLE test_info ( user_id int NOT NU ...
- 教老婆学Linux运维(一)初识Linux
零.前言 之一 为什么写这个系列?为什么是Linux? 老婆自从怀孕以后,辞职在家待了好几年了,现在时常感觉与社会脱节.所以想找个工作. 做了多年程序员,有点人脉也都基本是在IT圈子里,只能帮忙找找I ...
- java并发编程(十八)----(线程池)java线程池框架Fork-Join
还记得我们在初始介绍线程池的时候提到了Executor框架的体系,到现在为止我们只有一个没有介绍,与ThreadPoolExecutor一样继承与AbstractExecutorService的For ...
- javascript数组去重 js数组去重
数组去重的方法 一.利用ES6 Set去重(ES6中最常用) function unique (arr) { return Array.from(new Set(arr)) } var arr = [ ...
- javascript中的浅拷贝和深拷贝(拷贝引用和拷贝实例)
作者:千锋教育链接:https://www.zhihu.com/question/23031215/answer/326129003来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
