Translate

Views

Sunday, August 25, 2024

Solution Uva: 10338 - Mischievous Children

 

 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10338 - Mischievous Children AcceptedPython1.0200.00044645 mins ago

Suggest:

1/ RESULT = ALL CASE  - SAME CASE

2/ ALL CASE  = n! (n is length string)

3/ SAME CASE = a! * b! * ... * c! (with a,b,c is number of same chars ) 


from functools import cache

@cache
def fac(n):
    if n == 1:
        return 1
    return fac(n - 1) * n


n = int(input())
for i in range(1, n+1):
    s = input()
   
    d = {}
    for c in s:
        if c not in d:
            d[c] = 1
        else:
            d[c] += 1

    r = fac(len(s))
    for key in d:
        r //= fac(d[key])
    print(f'Data set {i}: {r}')

Monday, August 19, 2024

Solution UVA: 10268 - 498-bis


 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10268 - 498-bis AcceptedC++110.0200.0007051 mins ago

Susgest:

- Use pow default function couldn't AC so we need code Pow binary function  

#include <bits/stdc++.h>
#define int long long
using namespace std;

string line1, line2;

long long Pow(long long a, long long b) {
    if (!b) return 1;
    long long x = Pow(a, b / 2);
    if (b % 2 == 0)
        return x * x;
    else
        return x * x * a;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    while(getline(cin, line1)){
        getline(cin, line2);
               
        stringstream l1(line1);
        stringstream l2(line2);

        int x;  l1 >> x;
       
        vector<int> a;
        int v;

        while(l2 >> v) a.push_back(v);  
        reverse(a.begin(), a.end());

        int s = 0;
        for(int i=1; i<a.size(); i++)
            s += a[i]*i*Pow(x, i-1);
        cout<<s<<"\n";

    }
}