2020 hdu 多校 第6场 部分题解

1001 1001 1001 R o a d Road Road T o To To T h e The The 3 r d 3rd 3rd B u i l d i n g Building Building

思路:
说实话写出这题的时候挺兴奋的(因为本身是个弱鸡),坑点比较多,而且一个队友没来,我和另一个队友孤军奋战,我让mh和我一起读题,然后我们俩确定题意后,我们开始分别想,之后我想了一个多小时,我找到一个规律,首先这题要确定分数的底数要相同,呢么就要求相同的底数。然后我们可以画图来看:
2020 hdu 多校 第6场 部分题解_第1张图片
2020 hdu 多校 第6场 部分题解_第2张图片
2020 hdu 多校 第6场 部分题解_第3张图片

我们可以知道每一长度的和为 k ∗ s u m ( 1 + . . . . n ) − 前 缀 和 的 前 缀 − 后 缀 和 的 后 缀 k*sum(1+....n)-前缀和的前缀-后缀和的后缀 ksum(1+....n)即是答案,但是有一个坑点让我 w a wa wa了4发,就是上面这个公式取余后运算可能为负数,所以需要一个小技巧就是+ m o d mod mod
参考代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
//#define ll long long
const ll N = 1e3 + 5;
const ll maxn = 2e5 + 20;
const ll mod = 1000000007;
ll inv[maxn], vis[maxn], dis[maxn];
//ll fac[maxn], a[maxn], q[maxn], b[N], c[N];
//vector vec;
//typedef pair p;
//priority_queue, greater

> m; ll sum[maxn], a[maxn]; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } map<ll, ll> mp; ll ksm(ll a, ll b) { a %= mod; ll ans = 1ll; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1ll; } return ans; } ll dp[105][16005]; string p = "abacaba"; queue<ll> qk, q; vector<ll> vec; ll sumx[maxn], sumy[maxn], sumk[maxn]; int main() { ll t, n, ans; scanf("%lld", &t); while (t--) { memset(sum, 0, sizeof sum); memset(sumx, 0, sizeof sumx); memset(sumy, 0, sizeof sumy); memset(sumk, 0, sizeof sumk); scanf("%lld", &n); ans = 0; for (ll i = 1ll; i <= n; i++) scanf("%lld", &a[i]), sum[i] = (sum[i - 1ll] + a[i]) % mod; for (ll i = 1ll; i <= n; i++) sumx[i] = (sumx[i - 1ll] + sum[i]) % mod; ll k = n; for (ll i = 1ll; i <= n; i++) sumy[i] = (sumy[i - 1ll] + a[k]) % mod, k--; for (ll i = 1ll; i <= n; i++) sumk[i] = (sumk[i - 1ll] + sumy[i]) % mod; for (ll i = 1ll; i <= n; i++) { ans = (ans + ((((i * sum[n] % mod) - sumx[i - 1ll] - sumk[i - 1ll] + mod) % mod) * ksm(i, mod - 2ll) % mod)) % mod; } ll np = (((n + 1ll) * n) / 2ll) % mod; printf("%lld\n", ((ans % mod) * (ksm(np, mod - 2ll) % mod) % mod)); } }

1002 1002 1002 ( L i t t l e ( Little (Little R a b b i t ′ s Rabbit's Rabbits E q u a t i o n ) Equation ) Equation)

思路:
这题mh过的,但他交了两发re了,上面说除数为0了,他说他判断了,我帮他看了一下发现,判断除数为0前,先执行了除法,然后改掉就A了。

参考代码:

#include
#include
#include
#include
#include
#include
#include
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn=1000;
const int mod=998244353;
ll max(ll a,ll b)
{
    if(a>b) return a;
    else return b;
}
int main()
{
    char s[maxn],w[maxn];
    w['0']=0;
    w['1']=1;
    w['2']=2;
    w['3']=3;
    w['4']=4;
    w['5']=5;
    w['6']=6;
    w['7']=7;
    w['8']=8;
    w['9']=9;
    w['A']=10;
    w['B']=11;
    w['C']=12;
    w['D']=13;
    w['E']=14;
    w['F']=15;
    while(~scanf("%s",s))
    {
        ll len=strlen(s);
        ll a=0,b=0,c=0;
        ll ans=1,sum=0,flag=0,nnn,base=1;
        for(ll i=len-1; i>=0; --i)
        {
            if(s[i]!='=' && s[i]!='+' && s[i]!='-' && s[i]!='*' && s[i]!='/')
            {
                base=max(base,w[s[i]]);
            }
        }
        for(ll k=base+1; k<=16; ++k)
        {
            ans=1,sum=0;
            for(ll i=len-1; i>=0; --i)
            {
                if(s[i]!='=' && s[i]!='+' && s[i]!='-' && s[i]!='*' && s[i]!='/')
                {

                    sum=w[s[i]]*ans+sum;
                    ans*=k;
                }
                else
                {
                    if(s[i]=='=')
                    {
                        c=sum;
                        sum=0;
                        ans=1;
                    }
                    else
                    {
                        if(s[i]=='-') nnn=1;
                        if(s[i]=='+') nnn=2;
                        if(s[i]=='*') nnn=3;
                        if(s[i]=='/') nnn=4;
                        b=sum;
                        sum=0;
                        ans=1;
                    }
                }
            }
            a=sum;
            //printf("%d %d %d\n",a,b,c);
            //system("pause");
            if((a+b)==c && nnn==2)
            {
                flag=1;
                printf("%lld\n",k);
                break;
            }
            else if((a-b)==c && nnn==1)
            {
                flag=1;
                printf("%lld\n",k);
                break;
            }
            else if((a*b)==c && nnn==3)
            {
                flag=1;
                printf("%lld\n",k);
                break;
            }
            else if(b!=0 && (a/b)==c && nnn==4 && (a%b)==0)
            {
                flag=1;
                printf("%lld\n",k);
                break;
            }
        }
        if(flag==0)
            printf("-1\n");
    }
    return 0;
}

1009 1009 1009 ( D i v i s i b i l i t y ) ( Divisibility ) (Divisibility)

思路:
没有思路,我们也不会,没看懂,但是过了???最后半个多小时,我对mh说我随便莽啊,管他了!然后判断了一下奇偶就过了!!!!?我服了,之前写了一个多小时??就这??
参考代码:

 #include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
//#define ll long long
const ll N = 1e3 + 5;
const ll maxn = 2e5 + 20;
const ll mod = 1000000007;
ll inv[maxn], vis[maxn], dis[maxn];
//ll fac[maxn], a[maxn], q[maxn], b[N], c[N];
//vector vec;
//typedef pair p;
//priority_queue, greater

> m; ll sum[maxn], a[maxn]; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } map<ll, ll> mp; ll ksm(ll a, ll b) { a %= mod; ll ans = 1ll; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1ll; } return ans; } ll dp[105][16005]; string p = "abacaba"; queue<ll> qk, q; vector<ll> vec; ll sumx[maxn], sumy[maxn], sumk[maxn]; int main() { ll t, n, ans; scanf("%lld", &t); while (t--) { // memset(sum, 0, sizeof sum); // memset(sumx, 0, sizeof sumx); // memset(sumy, 0, sizeof sumy); // memset(sumk, 0, sizeof sumk); // scanf("%lld", &n); // ans = 0; // for (ll i = 1ll; i <= n; i++) // scanf("%lld", &a[i]), sum[i] = (sum[i - 1ll] + a[i]) % mod; // for (ll i = 1ll; i <= n; i++) // sumx[i] = (sumx[i - 1ll] + sum[i]) % mod; // ll k = n; // for (ll i = 1ll; i <= n; i++) // sumy[i] = (sumy[i - 1ll] + a[k]) % mod, k--; // for (ll i = 1ll; i <= n; i++) // sumk[i] = (sumk[i - 1ll] + sumy[i]) % mod; // for (ll i = 1ll; i <= n; i++) // { // ans = (ans + ((((i * sum[n] % mod) - sumx[i - 1ll] - sumk[i - 1ll] + mod) % mod) * ksm(i, mod - 2ll) % mod)) % mod; // } // ll np = (((n + 1ll) * n) / 2ll) % mod; // printf("%lld\n", ((ans % mod) * (ksm(np, mod - 2ll) % mod) % mod)); ll n, x; cin >> n >> x; if ((n % x) == 1) cout << "T" << endl; else { cout << "F" << endl; } } }

你可能感兴趣的:(笔记)