2019dx#7

 

SolvedPro.IDTitleRatio(Accepted / Submitted)
 1001A + B = C                  10.48%(301/2872)
 1002Bracket Sequences on Tree11.27%(16/142)
 1003Cuber Occurrence6.67%(1/15)
 1004Data Structure Problem23.08%(3/13)
 1005Equation0.00%(0/63)
 1006Final Exam          推公式,田忌赛马5.06%(297/5872)
 1007Getting Your Money Back12.42%(20/161)
 1008Halt Hater14.77%(61/413)
 1009Intersection of Prisms0.00%(0/2)
 1010Just Repeat          博弈,贪心15.04%(128/851)
 1011Kejin Player          期望DP21.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 = 998244353;

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x=f?-x:x;
}
/**********showtime************/
            const int maxn = 1e5+9;
            const int N = 1e5+9;
            char a[maxn],b[maxn],c[maxn];
            char d[maxn];
            int mod1 = 998244353, mod2 = 1e9+7;
            int ten1[N], ten2[N];
            unordered_map<int,int>mp1,mp2;
            void init(){
                ten1[0] = ten2[0] = 1;
                mp1[1] = mp2[1] = 0;
                for(int i=1; i<N; i++)
                {
                    ten1[i] = 1ll*ten1[i-1] * 10 % mod1;
                    ten2[i] = 1ll*ten2[i-1] * 10 % mod2;

                    mp1[ten1[i]] = i;
                    mp2[ten2[i]] = i;
                }
            }
            ll ksm(ll a, ll b, ll mod){
                ll res = 1;
                while(b > 0) {
                    if(b & 1) res = res * a % mod;
                    a = a * a % mod;
                    b = b >> 1;
                }
                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 = 0, cntb = 0, cntc = 0;
                while(a[alen-1] == '0') alen--, cnta ++;
                while(b[blen-1] == '0') blen--, cntb ++;
                while(c[clen-1] == '0') clen--, cntc ++;
                int kk = max(cnta, max(cntb, cntc));
                a[alen] = '\0';
                b[blen] = '\0';
                c[clen] = '\0';
                ll A1 = 0, B1 = 0, C1 = 0;
                ll A2 = 0, B2 = 0, C2 = 0;

                for(int i=0; i<alen; i++){
                    A1 = (A1 * 10 + (a[i] - '0') ) % mod1;
                    A2 = (A2 * 10 + (a[i] - '0') ) % mod2;
                }

                for(int i=0; i<blen; i++){
                    B1 = (B1 * 10 + (b[i] - '0') ) % mod1;
                    B2 = (B2 * 10 + (b[i] - '0') ) % mod2;
                }

                for(int i=0; i<clen; i++){
                    C1 = (C1 * 10 + (c[i] - '0') ) % mod1;
                    C2 = (C2 * 10 + (c[i] - '0') ) % mod2;
                }

                int k1 = (A1 + B1) % mod1 * ksm(C1, mod1-2, mod1) % mod1;
                if(mp1.count(k1))k1 = mp1[k1];
                else k1 = -1;
                int k2 = (A2 + B2) % mod2 * ksm(C2, mod2-2, mod2) % mod2;
                if(mp2.count(k2))k2 = mp2[k2];
                else k2 = -1;
                if(k1 == k2 && k1 >= 0) {
                    printf("%d %d %d\n", kk - cnta, kk - cntb, kk + k1 - cntc);
                    continue;
                }

                k1 = (C1 - B1) % mod1;
                if(k1 < 0) k1 += mod1;
                k1 = k1 * ksm(A1, mod1-2, mod1) % mod1;
                if(mp1.count(k1))k1 = mp1[k1];
                else k1 = -1;

                k2 = (C2 - B2) % mod2;
                if(k2 < 0) k2 += mod2;
                k2 = k2 * ksm(A2, mod2-2, mod2) % mod2;
                if(mp2.count(k2))k2 = mp2[k2];
                else k2 = -1;
                if(k1 == k2 && k1 >= 0) {
                    printf("%d %d %d\n", kk + k1 - cnta, kk - cntb, kk - cntc);
                    continue;
                }

                k1 = (C1 - A1) % mod1;
                if(k1 < 0) k1 += mod1;
                k1 = k1 * ksm(B1, mod1-2, mod1) % mod1;
                if(mp1.count(k1))k1 = mp1[k1];
                else k1 = -1;

                k2 = (C2 - A2) % mod2;
                if(k2 < 0) k2 += mod2;
                k2 = k2 * ksm(B2, mod2-2, mod2) % mod2;
                if(mp2.count(k2))k2 = mp2[k2];
                else k2 = -1;
                if(k1 == k2 && k1 >= 0) {
                    printf("%d %d %d\n", kk  - cnta, kk  + k1 - cntb, kk - cntc);
                    continue;
                }
                puts("-1");
            }
            return 0;
}
View Code

 

 

 

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 = 998244353;

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',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 + 1) / (n - k + 1);
                if((m+1) % (n - k + 1)) tmp++;
                ll ans = (k - 1) * tmp + m+ 1;
                printf("%lld\n", ans);
            }

            return 0;
}
View Code

 

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 = 998244353;

template<typename T>
inline T read(T&x){
    x=0;int f=0;char ch=getchar();
    while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',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 = 0;
                ll m = min(x, y);

                ans += m * min(a, 2ll * b);
                ll yu = x + y - m - m;
                ans += (yu / 2) * min(2ll * a , 2ll * b);

                if(yu % 2 == 1) 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-1, y));
                ans = min(ans, check(x, y+1));
                ans = min(ans, check(x-1, y+1));
                printf("%lld\n", ans);
            }
            return 0;
}
View Code

 

转载于:https://www.cnblogs.com/ckxkexing/p/11341725.html

``` <!DOCTYPE html> <html> <head> <title></title> </head> <style> * { padding: 0; margin: 0; } html, body { height: 100%; padding: 0; margin: 0; background: #000; } canvas { position: absolute; width: 100%; height: 100%; } .aa { position: fixed; left: 50%; bottom: 10px; color: #ccc; } </style> <body> <canvas id="pinkboard"></canvas> <script> /* * Settings */ var settings = { particles: { length: 500, // maximum amount of particles duration: 2, // particle duration in sec velocity: 100, // particle velocity in pixels/sec effect: -0.75, // play with this for a nice effect size: 30 // particle size in pixels } }; /* * RequestAnimationFrame polyfill by Erik M?ller */ (function () { var b = 0; var c = ["ms", "moz", "webkit", "o"]; for (var a = 0; a < c.length && !window.requestAnimationFrame; ++a) { window.requestAnimationFrame = window[c[a] + "RequestAnimationFrame"]; window.cancelAnimationFrame = window[c[a] + "CancelAnimationFrame"] || window[c[a] + "CancelRequestAnimationFrame"]; } if (!window.requestAnimationFrame) { window.requestAnimationFrame = function (h, e) { var d = new Date().getTime(); var f = Math.max(0, 16 - (d - b)); var g = window.setTimeout(function () { h(d + f); }, f); b = d + f; return g; }; } if (!window.cancelAnimationFrame) { window.cancelAnimationFrame = function (d) { clearTimeout(d); }; } })(); /* * Point class */ var Point = (function () { function Point(x, y) { this.x = typeof x !== "undefined" ? x : 0; this.y = typeof y !== "undefined" ? y : 0; } Point.prototype.clone = function () { return new Point(this.x, this.y); }; Point.prototype.length = function (length) { if (typeof length == "undefined") return Math.sqrt(this.x * this.x + this.y * this.y); this.normalize(); this.x *= length; this.y *= length; return this; }; Point.prototype.normalize = function () { var length = this.length(); this.x /= length; this.y /= length; return this; }; return Point; })(); /* * Particle class */ var Particle = (function () { function Particle() { this.position = new Point(); this.velocity = new Point(); this.acceleration = new Point(); this.age = 0; } Particle.prototype.initialize = function (x, y, dx, dy) { this.position.x = x; this.position.y = y; this.velocity.x = dx; this.velocity.y = dy; this.acceleration.x = dx * settings.particles.effect; this.acceleration.y = dy * settings.particles.effect; this.age = 0; }; Particle.prototype.update = function (deltaTime) { this.position.x += this.velocity.x * deltaTime; this.position.y += this.velocity.y * deltaTime; this.velocity.x += this.acceleration.x * deltaTime; this.velocity.y += this.acceleration.y * deltaTime; this.age += deltaTime; }; Particle.prototype.draw = function (context, image) { function ease(t) { return --t * t * t + 1; } var size = image.width * ease(this.age / settings.particles.duration); context.globalAlpha = 1 - this.age / settings.particles.duration; context.drawImage( image, this.position.x - size / 2, this.position.y - size / 2, size, size ); }; return Particle; })(); /* * ParticlePool class */ var ParticlePool = (function () { var particles, firstActive = 0, firstFree = 0, duration = settings.particles.duration; function ParticlePool(length) { // create and populate particle pool particles = new Array(length); for (var i = 0; i < particles.length; i++) particles[i] = new Particle(); } ParticlePool.prototype.add = function (x, y, dx, dy) { particles[firstFree].initialize(x, y, dx, dy); // handle circular queue firstFree++; if (firstFree == particles.length) firstFree = 0; if (firstActive == firstFree) firstActive++; if (firstActive == particles.length) firstActive = 0; }; ParticlePool.prototype.update = function (deltaTime) { var i; // update active particles if (firstActive < firstFree) { for (i = firstActive; i < firstFree; i++) particles[i].update(deltaTime); } if (firstFree < firstActive) { for (i = firstActive; i < particles.length; i++) particles[i].update(deltaTime); for (i = 0; i < firstFree; i++) particles[i].update(deltaTime); } // remove inactive particles while ( particles[firstActive].age >= duration && firstActive != firstFree ) { firstActive++; if (firstActive == particles.length) firstActive = 0; } }; ParticlePool.prototype.draw = function (context, image) { // draw active particles if (firstActive < firstFree) { for (i = firstActive; i < firstFree; i++) particles[i].draw(context, image); } if (firstFree < firstActive) { for (i = firstActive; i < particles.length; i++) particles[i].draw(context, image); for (i = 0; i < firstFree; i++) particles[i].draw(context, image); } }; return ParticlePool; })(); /* * Putting it all together */ (function (canvas) { var context = canvas.getContext("2d"), particles = new ParticlePool(settings.particles.length), particleRate = settings.particles.length / settings.particles.duration, // particles/sec time; // get point on heart with -PI <= t <= PI function pointOnHeart(t) { return new Point( 160 * Math.pow(Math.sin(t), 3), 130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25 ); } // creating the particle image using a dummy canvas var image = (function () { var canvas = document.createElement("canvas"), context = canvas.getContext("2d"); canvas.width = settings.particles.size; canvas.height = settings.particles.size; // helper function to create the path function to(t) { var point = pointOnHeart(t); point.x = settings.particles.size / 2 + (point.x * settings.particles.size) / 350; point.y = settings.particles.size / 2 - (point.y * settings.particles.size) / 350; return point; } // create the path context.beginPath(); var t = -Math.PI; var point = to(t); context.moveTo(point.x, point.y); while (t < Math.PI) { t += 0.01; // baby steps! point = to(t); context.lineTo(point.x, point.y); } context.closePath(); // create the fill context.fillStyle = "#ea80b0"; context.fill(); // create the image var image = new Image(); image.src = canvas.toDataURL(); return image; })(); // render that thing! function render() { // next animation frame requestAnimationFrame(render); // update time var newTime = new Date().getTime() / 1000, deltaTime = newTime - (time || newTime); time = newTime; // clear canvas context.clearRect(0, 0, canvas.width, canvas.height); // create new particles var amount = particleRate * deltaTime; for (var i = 0; i < amount; i++) { var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random()); var dir = pos.clone().length(settings.particles.velocity); particles.add( canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y ); } // update and draw particles particles.update(deltaTime); particles.draw(context, image); } // handle (re-)sizing of the canvas function onResize() { canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; } window.onresize = onResize; // delay rendering bootstrap setTimeout(function () { onResize(); render(); }, 10); })(document.getElementById("pinkboard")); </script> </body> </html> ``` ![示例图片](https://devbit-static.oss-cn-beijing.aliyuncs.com/devbit-static/img/heart.png)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值