CSU 1027: Smallbox魔方 1031: Parsing Real Numbers 1032: OSU! Scoring System 1033: 五一步行街购物

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nameofcsdn/article/details/79958840

1027: Smallbox魔方

代码:

#include<stdio.h>
#include<string.h>
#define MAXD 15010
#define MOD 1000000007
int N, M, a[10], b[10], ny[MAXD];
long long exgcd(long long a, long long b, long long &x, long long &y)
{
    if(b == 0)
        x = 1, y = 0;
    else
        exgcd(b, a % b, y, x), y -= x * (a / b);
}
void prepare()
{
    int i;
    long long x, y;
    for(i = 1; i <= 15000; i ++)
    {
        exgcd(i, MOD, x, y);
        x = (x % MOD + MOD) % MOD;
        ny[i] = x;
    }
}
void init()
{
    int i;
    scanf("%d", &N);
    M = 6 * N * N;
    for(i = 0; i < 6; i ++)
        scanf("%d", &a[i]);
}
long long comb(int n, int m)
{
    int i;
    long long ans = 1;
    for(i = n - m + 1; i <= n; i ++)
        ans = ans * i % MOD;
    for(i = 2; i <= m; i ++)
        ans = ans * ny[i] % MOD;
    return ans;
}
long long calculate(int m)
{
    int i, j, n = 0;
    long long ans = 1;
    for(i = 0; i < 6; i ++)
    {
        if(b[i] % m != 0)
            return 0;
        b[i] /= m;
        n += b[i];
    }
    for(i = 0; i < 6; i ++)
    {
        ans = ans * comb(n, b[i]) % MOD;
        n -= b[i];
    }
    return ans;
}
long long frotate()
{
    int i, j;
    long long ans = 0;
    // 0
    memcpy(b, a, sizeof(a));
    ans = (ans + calculate(1)) % MOD;
    // 90 270
    if(N & 1)
    {
        for(i = 0; i < 6; i ++)
            for(j = 0; j < 6; j ++)
            {
                memcpy(b, a, sizeof(a));
                -- b[i], -- b[j];
                if(b[i] < 0 || b[j] < 0)
                    continue;
                ans = (ans + 6 * calculate(4)) % MOD;
            }
    }
    else
    {
        memcpy(b, a, sizeof(a));
        ans = (ans + 6 * calculate(4)) % MOD;
    }
    // 180
    if(N & 1)
    {
        for(i = 0; i < 6; i ++)
            for(j = 0; j < 6; j ++)
            {
                memcpy(b, a, sizeof(a));
                -- b[i], -- b[j];
                if(b[i] < 0 || b[j] < 0)
                    continue;
                ans = (ans + 3 * calculate(2)) % MOD;
            }
    }
    else
    {
        memcpy(b, a, sizeof(a));
        ans = (ans + 3 * calculate(2)) % MOD;
    }
    return ans;
}
long long erotate()
{
    int i;
    long long ans = 0;
    // 180
    memcpy(b, a, sizeof(a));
    ans = (6 * calculate(2)) % MOD;
    return ans;
}
long long vrotate()
{
    int i;
    long long ans = 0;
    // 60 120
    memcpy(b, a, sizeof(a));
    ans = (8 * calculate(3)) % MOD;
    return ans;
}
void solve()
{
    long long ans = 0;
    ans = (ans + frotate()) % MOD;
    ans = (ans + erotate()) % MOD;
    ans = (ans + vrotate()) % MOD;
    ans = ans * ny[24] % MOD;
    printf("%lld\n", ans);
}
int main()
{
    int t;
    prepare();
    scanf("%d", &t);
    while(t --)
    {
        init();
        solve();
    }
    return 0;
}


1031: Parsing Real Numbers

代码:

# include <stdio.h>
# include <ctype.h>
# include <string.h>

# define BITSET(i) ((sign)|=(char)(0x1<<(i)))
# define GETBIT(i) ((sign)>>(i) & (0x1))

char a[1000];
char sign;

/* sign: 0 - wrong?
         1 - coeff sign
         2 - integ
         3 - digit
         4 - floatdigit
         5 - e
         6 - e sign
         7 - e integ
*/

int main()
{
    int i, T, len, judge;
    scanf("%d", &T);
    while (T > 0)
    {
        scanf("%s", a);
        len = strlen(a);

        sign = 0;
        i = 0;
        if (a[i]=='+' || a[i]=='-') { BITSET(1); ++i;}
        while (isdigit(a[i])) { BITSET(2); ++i;}
        if (a[i]=='.') { BITSET(3); ++i;}
        while (isdigit(a[i])) { BITSET(4); ++i;}
        if (a[i]=='E' || a[i]=='e') { BITSET(5); ++i;}
        if (a[i]=='+' || a[i]=='-') { BITSET(6); ++i;}
        while (isdigit(a[i])) { BITSET(7); ++i;}

        if ((a[i] != '\0')
                || (GETBIT(3) && !GETBIT(2) && !GETBIT(4))
                || ((GETBIT(5)||GETBIT(6)) && !GETBIT(7))
                || (len && !GETBIT(2) && !GETBIT(4)))
            BITSET(0);

        if (GETBIT(0)) printf("NO\n");
        else printf("YES\n");
        --T;
    }

    return 0;
}


1032: OSU! Scoring System

代码:

#include <stdio.h>  
  
int main()  
{  
    int cas,com,mis,num50,num300;  
    scanf("%d",&cas);  
    double d,m,l,hsum,sum,all,num;  
    while(cas--)  
    {  
        scanf("%lf %lf %lf",&d,&m,&l);  
        hsum=0,sum=0,all=0;  
        com=mis=num50=num300=0;  
        for(int i=0;i<l;i++)  
        {  
            scanf("%lf",&num);  
            all+=num+num*( (com-1>0?com-1:0)*d*m )/25;  
            if(num==0) com=0,mis++;  
            else com++;  
            hsum+=num;  
            if(num==50) num50++;  
            if(num==300) num300++;  
        }  
        printf("%.2lf %.2lf%% ",all,hsum*100/(l*300));  
        double temp=hsum*100/(l*300);  
        if(temp==100) printf("SS\n");  
        else  
        {  
            double temp50=num50*50*100/(l*300);  
            double temp300=num300*300*100/(l*300);  
            if(temp300>=90 &&temp50<=1 &&mis==0)  
                printf("S\n");  
            else if(temp300>=80 &&mis==0 || temp300>=90)  
                printf("A\n");  
            else if(temp300>=70&&mis==0 ||temp300>=80)  
                printf("B\n");  
            else if(temp300>=60)  
                printf("C\n");  
            else printf("D\n");  
        }  
    }  
    return 0;  
}  


1033: 五一步行街购物

代码:

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int dp[110];
int m, n;
int gou[101];
int shang[100001][2], top;
int main()
{
    while(scanf("%d%d",&m,&n)!=EOF)
    {
        if(n==0&&m==0)break;
        int i, j, a, b;
        map<int,bool>mp;
        top = 1;
        mp.clear();
        for(i=1; i<=m; i++)
        {
            scanf("%d",&gou[i]);
            mp[gou[i]] = true;
        }
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&a,&b);
            if(mp[a])
            {
                shang[top][0] = a;
                shang[top][1] = b;
                top++;
            }
        }
        dp[0] = 0;
        for(i=1; i<=m; i++)dp[i] = INF;
        for(i=1; i<top; i++)
        {
            for(j=m; j>0; j--)
            {
                if(shang[i][0] == gou[j])
                {
                    dp[j] = min(dp[j], dp[j-1] + shang[i][1]);
                }
            }
        }
        if(dp[m]==INF)
        {
            printf("Impossible\n");
        }
        else
        {
            printf("%d\n",dp[m]);
        }
    }
    return 0;
}

阅读更多

Essay Scoring System

05-20

Problem DescriptionnProfessor Binns has finally got tired of scoring essays himself and implemented an automatic essay scoring system to help him screen the numerous essays. Strongly against such an idea, you decided to generate a meaningless essay which can get high mark in his system to prove that his system does not work at all. You've obtained the rules used by Binns's system to score the essay, they're as follows:n a) The word in the essay must be from a particular set of words. If not, the essay will receive a score zero and is automatically rejected.n b) Every word in the specified set has a positive integer associated with it, indicating the score the submitter will get for using that word once.n c) A word can be used in several different ways; for example, in English, the word “word” can be used as both a noun and a verb. Every occurrence of specific patterns (like verb – adjective – noun) will earn the submitter a particular score.n In particular, it is allowed for a word to be interpreted in different ways in different patterns.nYou're interested in generating an essay of a specified length with maximum possible score. n nnInputnThere are multiple test cases in the input file. Each test case starts with three integers N, M and K, (1 <= N <= 100, 0 <= M <= 8, 0 <= K <= 6), the length of the essay to generate, the number of words in the dictionary and the number of patterns, respectively. The following M lines describe the words in the dictionary; each line consists of two integers, Wi, and Ti, (0 <= Wi <= 2000, 1 <= Ti <= 5), representing the score submitter gets every time he/she uses the word, and the number of ways the word can be used. The next part of the input describes the patterns. Each of the K lines describes one pattern, beginning with two integers, Wi, and Ci, (0 <= Wi <= 2000, 1 <= Ci <= 6), indicating the score one can get every time the pattern is used, and the number of consecutive parts in the pattern; followed by Ci integers describing the language parts in the pattern. It is guaranteed that the total number of ways to use a word does not exceed 5; furthermore, the total number of parts contained in all patterns (sum of all Cis) will not exceed 25.nThere is a blank line after each test case. Input ends with End-of-File.n nnOutputnFor every test case, you should output one integer on a separate line, the maximum score one can get, in the format as indicated in the sample output.n nnSample Inputn2 3 2n4 3 0 1 2n5 2 2 3n1 2 0 4n1 2 1 3n10 2 4 2nn2 3 2n4 3 0 1 2n5 2 2 3n1 2 0 4n1 2 1 3n2 2 4 2n nnSample OutputnCase 1: 16nCase 2: 10

没有更多推荐了,返回首页