1. ACM UVA-10105

    二項式定理。 題目

    //ignore header files
    
    int main(int argc, char const* argv[])
    {
        int n,k;
        while(scanf("%d %d",&n,&k) != EOF){
            int ans = 1;
            for(int j = 1;j <= n;j++)
                ans = ans*j;
            while(k--){
                int m;
                scanf("%d",&m);
                for(int j = 1;j <= m;j++)
                    ans ...

    Read more...


  2. ACM UVA-10106

    大數乘法。

    int ans[600];
    int main(int argc, char const* argv[])
    {
        string xx,yy;
        while(getline(cin,xx) && getline(cin,yy)){
            int xl = xx.length();
            int yl = yy.length();
            int x[300];
            int y[300];
            for(int i = 0;i<xl || i<yl;i++){
                if(i<xl)
                    x[i] = xx ...

    Read more...


  3. ACM UVA-10127

    題目

    int main(int argc, char const* argv[])
    {
        int n;
        while (~scanf("%d",&n)) {
            string ans;
            int remain = 0;
            if(n == 0)
                printf("0\n");
            else{
                do{
                    remain = (remain*10+1)%n;
                    ans = ans+"1";
                }while(remain != 0);
                printf("%d\n",ans.length());
            }
    
        }
    
        return 0;
    }
    

    Read more...


  4. ACM UVA-10193

    題目

    int foo(char *s1){
        int l = strlen(s1);
        l--;
        int f = 1;
        int sum = 0;
        while(l >= 0){
            sum = sum+(s1[l]-'0')*f;
            l--;
            f = f*2;
        }
        return sum;
    }
    int gcd(int a,int b){
        return b == 0?a:gcd(b,a%b);
    }
    int main(int argc, char ...

    Read more...


  5. ACM UVA-10227

    題目

    int main(int argc, char const* argv[])
    {
        int ap;
    
        while (scanf("%d",&ap)!= EOF) {
            for(int kk = 0;kk<ap;kk++){
                int t,p;
                scanf("%d %d",&p,&t);
                vector< vector<int> > pt(p,vector<int>(t));
                vector< vector<int> > pp(p);
                string line;
                getline(cin,line);
                while(getline ...

    Read more...


  6. ACM UVA-10235

    題目

    //ignore header files
    int main(int argc, char const* argv[])
    {
        bool N[2000000];
        N[0] = true;
        N[1] = true;
        for(unsigned long long i = 2;i <2000000;i++){
            if(!N[i]){
                for(unsigned long long j = i+i;j<2000000;j = j+i){
                   N[j] = true; 
                }
            }
        }
        int n;
        while ...

    Read more...


  7. ACM UVA-10268

    題目

    //ignore header files
    int main(int argc, char const* argv[])
    {
        int x;
        while(scanf("%d",&x) != EOF){
            string line;
            getline(cin,line);
            getline(cin,line);
            istringstream stream(line);
            int an;
            int n = 0;
            int sum = 0;
            while(stream>>an){
                n++;
            }
            n--;
            istringstream s2(line);
            while(n>0){
                s2>>an ...

    Read more...


  8. ACM UVA-10299

    質數題

    //ignore header files
    #define max 100000
    bool is_prime[max+1];
    unsigned long long prime[50000+1];
    int main(int argc, char const* argv[])
    {
    
        int m = 0;
        for(unsigned long long i = 2;i <= max;i++){
            if(!is_prime[i]){
                prime[m++] = i;
                for(unsigned long long j = i*i;j ...

    Read more...


  9. ACM UVA-10305

    單純的topological sort。

    //ignore header files
    int main(int argc, char const* argv[])
    {
        int n,m;
        while(scanf("%d %d",&n,&m) && !(n == 0 && m == 0)){
            vector<int> G[105];
            int ref[105] = {0};
            while(m--){
                int a,b;
                scanf("%d %d",&a,&b);
                G[a].push_back(b);
                ref[b]++;
            }
            //topological ...

    Read more...


  10. ACM UVA-10323

    題目

    int main(int argc, char const* argv[])
    {
        unsigned long long factorial[14];
        factorial[0] = 1;
        for(int i = 1;i <= 13;i++)
            factorial[i] = i*factorial[i-1];
        int n;
        while(~scanf("%d",&n)){
            if(n >= 0){
                if(n  >= 8 && n <= 13){
                    printf("%llu\n",factorial[n]);
                }else if ...

    Read more...


« Page 9 / 13 »