SDNUOJ——[1550-1552]

這幾天好像都在瘋狂的查MFC的資料~~~~,終於想起來要 寫一篇自己出的題的題解的博客了。。

挺奇怪的,寫自己出的題的題解,不過還是有必要寫一下的,畢竟是一次屬於自己的思考嘛~~~~

問題蟲洞——1550:1550.你的心態炸了嘛?

 

黑洞內窺:

題目給出多組數據,每組數據包括n,a,b和c四個數字。

要求你求出第n個可以被a或b或c整除的正整數。

(1<=n, a, b, c <=10^9,a!=b!=c。答案保證在2^31-1範圍內)

 

思維光年:

容斥+二分(直接看代碼)

 

ACcode:

//#include<bits/stdc++.h>
#include  <stdio.h>
#include <iostream>
#include<algorithm>
#include      <map>
#include      <set>
#include   <vector>
#include    <queue>
#include    <stack>
#include <stdlib.h>
#include  <cstring>
#include <string.h>
#include   <string>
#include   <math.h>
using namespace std;
typedef long long ll;
#define MAXN 2000000010;
#define INF 0x3f3f3f3f//將近ll類型最大數的一半,而且乘2不會爆ll

ll gcd(ll a, ll b){return b==0? a: gcd(b, a%b);}
int main()
{
    ll n, a, b, c;
    while(~scanf("%lld %lld %lld %lld", &n, &a, &b, &c))
    {
        ll ab = a*b/gcd(a, b);
        ll ac = a*c/gcd(a, c);
        ll bc = b*c/gcd(b, c);
        ll abc = a*bc/gcd(a, bc);
        ll l=0, r=MAXN;
        while(l < r)
        {
            ll mid = l + (r-l)/2;
            ll ans = mid/a+mid/b+mid/c-mid/ab-mid/bc-mid/ac+mid/abc;
            if(ans<n) l = mid+1;
            else r = mid;
        }
        cout << l << '\n';
    }
    return 0;
}

 

 

問題蟲洞——1552:1552.暢遊王者峽谷

 

黑洞內窺:

Treatment,Sprint,Smite,End,Rage,Interfere,Vertigo,Purify,Weaken,Flash

十個召喚師技能無限重複的排成一個序列(Treatment開始,Flash結束,然後不斷重複),夫子輸入一個n(多組),求第(1^1+2^2+3^3+4^4+5^5+……+(n-1)^n-1+n^n)個召喚師技能是什麼?(1<=n<=500000)

 

思維光年:

快速冪暴力

 

ACcode:

//#include<bits/stdc++.h>
#include  <stdio.h>
#include <iostream>
#include<algorithm>
#include      <map>
#include      <set>
#include   <vector>
#include    <queue>
#include    <stack>
#include <stdlib.h>
#include  <cstring>
#include <string.h>
#include   <string>
#include   <math.h>
using namespace std;
typedef long long ll;
#define MAXN 500005
#define INF 0x3f3f3f3f//將近ll類型最大數的一半,而且乘2不會爆ll

int a[MAXN];
string s[11] = {"0", "Treatment", "Sprint", "Smite", "End", "Rage",
                "Interfere", "Vertigo", "Purify", "Weaken", "Flash"};
ll qpow(ll a, ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans = ans*a%10;
        a = a*a%10;
        b >>= 1;
    }
    return ans%10;
}

void init()
{
    for(ll i=1; i<=MAXN; ++i)
        a[i] = (a[i-1]+qpow(i, i))%10;
}

int main()
{
    init();
    int n;
    while(~scanf("%d", &n))
        if(a[n] == 0) cout << s[10] << '\n';
        else cout << s[a[n]] << '\n';
    return 0;
}

 

我就出了這兩題,沒什麼好考察的,題目也是中文~~~~emmm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章