码迷,mamicode.com
首页 > 其他好文 > 详细

女生赛训练 2

时间:2019-06-09 12:45:48      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:lan   while   can   ons   problem   target   pen   nec   scan   

A - Automatic Judge

技术图片
#include <bits/stdc++.h>
using namespace std;
int vis[1200],timing[1200];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m;
        scanf("%d%d",&n,&m);
        memset(vis,0,sizeof(vis));
        memset(timing,0,sizeof(timing));
        int sum=0,all=0;
        for(int i=1;i<=m;i++)
        {
            int x;
            int h,m;
            string ans;
            scanf("%d",&x);
            scanf("%d:%d",&h,&m);
            int Time=h*60+m;
            cin>>ans;
            if(ans=="AC")
            {
                if(vis[x]) continue;
                else
                {
                    sum++;
                    vis[x]=1;
                    all+=timing[x]+Time;
                }
            }
            else if(ans=="CE")
            {
                continue;
            }
            else
            {
                if(vis[x]) continue;
                else
                {
                    timing[x]+=20;
                }
            }
        }
        printf("%d %d\n",sum,all);
    }



    return 0;
}
View Code

B - Building Shops

技术图片
#include <bits/stdc++.h>
#define ll long long
#define db double
using namespace std;

const int mn = 3010;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const db eps = 1e-3;

ll dp[mn][5];
ll sum[mn];

struct node
{
    ll x, c;
} p[mn];
bool cmp(const node &a, const node &b)
{
    return a.x < b.x;
}

int main()
{
    int n;
    while (~scanf("%d", &n))
    {
        for (int i = 1; i <= n; i++)
            scanf("%lld %lld", &p[i].x, &p[i].c);
            
        sort(p + 1, p + n + 1, cmp);
        
        sum[0] = 0;
        for (int i = 1; i <= n; i++)
            sum[i] = sum[i - 1] + p[i].x;
        
        for (int i = 1; i <= n; i++)
            dp[i][0] = dp[i][1] = inf;
        
        dp[1][1] = p[1].c;
        for (int i = 2; i <= n; i++)
        {
            dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + p[i].c;
            for (int j = 1; j < i; j++)
            {
                ll temp = sum[i] - sum[j] - (i - j) * p[j].x;
                dp[i][0] = min(dp[i][0], dp[j][1] + temp);
            }
            //cout << i << ‘ ‘ << dp[i][0] << ‘ ‘ << dp[i][1] << endl;
        }
        
        printf("%lld\n", min(dp[n][0], dp[n][1]));
    }
    
    
    return 0;
}
View Code

C - Coprime Sequence

技术图片
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll pre[maxn],sub[maxn];
ll a[maxn];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }

        pre[1]=a[1];
        for(int i=2;i<=n;i++)
        {
            pre[i]=__gcd(pre[i-1],a[i]);
        }
        sub[n]=a[n];
        for(int i=n-1;i>=1;i--)
        {
            sub[i]=__gcd(sub[i+1],a[i]);
        }
        ll ans=1;
        for(int i=2;i<=n-1;i++)
        {
            ans=max(ans,__gcd(pre[i-1],sub[i+1]));
        }
        ans=max(ans,sub[2]);
        ans=max(ans,pre[n-1]);
        printf("%lld\n",ans);
    }



}
View Code

E - Easy Summation

技术图片
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int mn = 1e5 + 10;
const ll mod = 1e9 + 7;

int main()
{
    int T;    scanf("%d", &T);
    while (T--)
    {
        ll n;int k;
        scanf("%lld %d", &n, &k);
        
        ll sum = 0;
        for (ll i = 1; i <= n; i++)
        {
            ll temp = 1;
            for (int j = 1; j <= k; j++)
                temp = temp * i % mod;
            sum = (sum + temp) % mod;
        }
        printf("%lld\n", sum);
    }
    
    return 0;
}
View Code

G - Graph Theory

技术图片
#include <bits/stdc++.h>
using namespace std;

const int mn = 1e5 + 10;

int a[mn];
int main()
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        int n;    scanf("%d", &n);
        
        a[1] = 2;
        for (int i = 2; i <= n; i++)
            scanf("%d", &a[i]);
        
        if (a[n] == 2 || n % 2 == 1)
        {
            printf("No\n");
            continue;
        }
        
        int temp = 0, flag = 1;
        for (int i = n; i >= 1; i--)
        {
            if (a[i] == 1)    temp++;
            else if (a[i] == 2)    temp--;
            if (temp < 0)
            {
                flag = 0;
                break;
            }
        }
        if (!flag)    printf("No\n");
        else    printf("Yes\n");
    }
    return 0;
}
View Code

H - Happy Necklace

技术图片
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;
ll N;

struct Matrix{
    ll m[3][3];
} in;

Matrix mul(Matrix x, Matrix y)
{
    Matrix z;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            z.m[i][j] = 0;
            for (int k = 0; k < 3; k++)
            {
                ll temp = (x.m[i][k] % mod) * (y.m[k][j] % mod) % mod;
                z.m[i][j] = (z.m[i][j] + temp) % mod;
            }
        }
    }
    return z;
}

Matrix qpow(ll n)
{
    Matrix ans;
    ans.m[0][0] = 1, ans.m[0][1] = 0, ans.m[0][2] = 0;
    ans.m[1][0] = 0, ans.m[1][1] = 1, ans.m[1][2] = 0;
    ans.m[2][0] = 0, ans.m[2][1] = 0, ans.m[2][2] = 1;
    
    Matrix t;
    t.m[0][0] = 1, t.m[0][1] = 1, t.m[0][2] = 0;
    t.m[1][0] = 0, t.m[1][1] = 0, t.m[1][2] = 1;
    t.m[2][0] = 1, t.m[2][1] = 0, t.m[2][2] = 0;
    
    while (n)
    {
        if (n & 1)
            ans = mul(ans, t);
        t = mul(t, t);
        n >>= 1;
    }
    return ans;
}

int main()
{
    int T;
    scanf("%d",&T);
    in.m[0][0] = 4, in.m[0][1] = 3, in.m[0][2] = 2;
    
    while(T--)
    {
        ll n;    scanf("%lld", &n);
        
        Matrix temp = qpow(n - 1);
        
//        for (int i = 0; i < 3; i++)
//        {
//            for (int j = 0; j < 3; j++)
//                printf("%d ", temp.m[i][j]);
//            printf("\n");
//        }
        
        Matrix res = mul(in, temp);
        
        printf("%lld\n", res.m[0][2]);
    }

    return 0;
}
View Code

 

女生赛训练 2

标签:lan   while   can   ons   problem   target   pen   nec   scan   

原文地址:https://www.cnblogs.com/zlrrrr/p/10993145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!