Contest1828 - 2019年我能变强组队训练赛热身赛

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1006;
const ll mod=1000000007;
int T;
int n,m;
ll k;
ll dp[1005][6],a[maxn];
ll gdp[1005][6];
//ll ans;
char f[maxn];
int main() {
    //freopen("1.txt","r",stdin);
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d%lld",&n,&m,&k);
        for(int i=1;i<=n;++i){
            scanf("%lld",a+i);
        }
        scanf("%s",f+1);
        for(int i=0;i<=n;++i){
            for(int j=0;j<=m;++j){
                dp[i][j]=-1000000000000009;
                gdp[i][j]=1000000000000009;
            }
        }
        dp[0][0]=k;
        gdp[0][0]=k;
        for(int i=1;i<=n;++i){
            for(int j=max(0,m-n+i);j<=min(i,m);++j){
                dp[i][j]=dp[i-1][j];
                gdp[i][j]=gdp[i-1][j];
                if(j==0)continue;
                if(f[j]==‘+‘){
                    dp[i][j]=max(dp[i][j],max(dp[i-1][j-1]+a[i],gdp[i-1][j-1]+a[i]));
                    gdp[i][j]=min(gdp[i][j],min(dp[i-1][j-1]+a[i],gdp[i-1][j-1]+a[i]));
                }
                else if(f[j]==‘-‘){
                    dp[i][j]=max(dp[i][j],max(dp[i-1][j-1]-a[i],gdp[i-1][j-1]-a[i]));
                    gdp[i][j]=min(gdp[i][j],min(dp[i-1][j-1]-a[i],gdp[i-1][j-1]-a[i]));
                }
                else if(f[j]==‘*‘){
                    dp[i][j]=max(dp[i][j],max(dp[i-1][j-1]*a[i],gdp[i-1][j-1]*a[i]));
                    gdp[i][j]=min(gdp[i][j],min(dp[i-1][j-1]*a[i],gdp[i-1][j-1]*a[i]));
                }
                else{
                    dp[i][j]=max(dp[i][j],max(dp[i-1][j-1]/a[i],gdp[i-1][j-1]/a[i]));
                    gdp[i][j]=min(gdp[i][j],min(dp[i-1][j-1]/a[i],gdp[i-1][j-1]/a[i]));
                }
                //ans=max(ans,dp[i][j]);
                //cout<<i<<‘ ‘<<j<<"dpij"<<‘ ‘<<dp[i][j]<<endl;
            }
        }
        printf("%lld\n",dp[n][m]);
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll n,m;

struct node
{
    ll a[9][9];
    node()
    {
        memset(a,0,sizeof(a));
    }
    node operator*(const node &b) const
    {
        node res;
        for (int i = 0; i < 9; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                res.a[i][j] = 0;
                for (int k = 0; k < 9; k++)
                {
                    res.a[i][j] = (res.a[i][j] + a[i][k] * b.a[k][j]%mod) % mod;
                }
            }
        }
        return res;
    }
};

node pow(node b,ll c)
{
    node res;
    for (int i=0; i<9; i++)
    {
        res.a[i][i]=1;
    }
    while (c)
    {
        if (c & 1)
        {
            res = res * b;
        }
        c >>= 1;
        b = b * b;
    }
    return res;
}
int a[9][9]={
    0,1,1,0,0,0,0,0,0,
    0,0,0,1,1,1,0,0,0,
    0,0,0,0,0,0,1,0,1,
    1,1,1,0,0,0,0,0,0,
    0,0,0,1,0,1,0,0,0,
    0,0,0,0,0,0,0,1,1,
    1,1,0,0,0,0,0,0,0,
    0,0,0,1,1,0,0,0,0,
    0,0,0,0,0,0,1,1,0};
node f;
int main()
{
    for (int i=0; i<9; i++)
    {
        for (int j=0; j<9; j++)
            f.a[i][j]=a[i][j];
    }
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%lld",&n);
        if (n==1){
            printf("3\n");
            continue;
        }
        if (n==2){
            printf("9\n");
            continue;
        }
        node ans=pow(f,n-2);
        ll ans1=0;
        for (int i=0; i<9; i++)
        {
            for (int j=0; j<9; j++)
            {
                ans1=(ans1+ans.a[i][j])%mod;
            }
        }
        printf("%lld\n",ans1);
    }
}
#include<bits/stdc++.h>

using namespace std;

#define rep(i,a,n) for(int i=a;i<n;i++)

#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;

const ll mod = 1e9+7;

ll powmod(ll a,ll b) {
    ll ret = 1;
    a%=mod;
    while(b) {
        if(b&1) ret = ret*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ret;
}
int _,n;

namespace linear_seq {
const int N = 10010;
ll res[N],base[N],_c[N],_md[N];
vector<int> Md;

void mul(ll *a,ll *b,int k) {
    for(int i=0; i<k+k; i++)
        _c[i] = 0;
    for(int i=0; i<k; ++i)
        if(a[i])
            for(int j=0; j<k; j++)
                _c[i+j] = (_c[i+j]+a[i]*b[j])%mod;

    for(int i=k+k-1; i>=k; i--)
        if(_c[i])
            for(int j=0; j<(int) Md.size(); j++)
                _c[i-k+Md[j]] = (_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
    for(int i=0; i<k; i++)
        a[i] = _c[i];
}

int solve(ll n,VI a,VI b) {
    ll ans = 0,pnt = 0;
    int k = SZ(a);
    for(int i=0; i<k; i++)
        _md[k-1-i] = -a[i];
    _md[k] = 1;
    Md.clear();
    for(int i=0; i<k; i++)
        if(_md[i]!=0)
            Md.push_back(i);
    for(int i=0; i<k; i++)
        res[i] = base[i] = 0;
    res[0] = 1;
    while((1ll<<pnt)<=n)
        pnt++;

    for(int p = pnt; p>=0; p--) {
        mul(res,res,k);
        if((n>>p)&1) {
            for(int i=k-1; i>=0; i--) res[i+1] = res[i];
            res[0]  = 0;
            for(int j=0; j<(int) Md.size(); ++j)
                res[Md[j]] = (res[Md[j]]-res[k]*_md[Md[j]])%mod;
        }
    }
    rep(i,0,k) ans = (ans+res[i]*b[i])%mod;
    if(ans<0) ans+=mod;
    return ans;
}

VI BM(VI s) {
    VI C(1,1),B(1,1);
    int L = 0,m = 1,b = 1;
    for(int n=0; n<(int)s.size(); ++n) {
        ll d = 0;
        for(int i=0; i<L+1; i++)
            d = (d+(ll)C[i]*s[n-i])%mod;
        if(d==0) ++m;
        else if(2*L<=n) {
            VI T=C;
            ll c = mod-d*powmod(b,mod-2)%mod;
            while(SZ(C)<SZ(B)+m)
                C.push_back(0);
            for(int i=0; i<(int) B.size(); i++)
                C[i+m] = (C[i+m]+c*B[i])%mod;
            L = n+1-L;
            B = T;
            b = d;
            m = 1;
        } else {
            ll c = mod-d*powmod(b,mod-2)%mod;
            while(SZ(C)<SZ(B)+m)
                C.push_back(0);
            for(int i=0; i<(int)B.size(); i++)
                C[i+m] = (C[i+m]+c*B[i])%mod;
            ++m;
        }
    }
    return C;
}

ll gao(VI a,ll n) {
    VI c = BM(a);
    c.erase(c.begin());
    for(int i=0; i<(int) c.size(); i++)
        c[i] = (mod-c[i])%mod;
    return (ll) solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
}

}

int main() {
    ll t;
    ll nnn;
    VI a;
    a.push_back(3);
    a.push_back(9);
    a.push_back(20);
    a.push_back(46);
    a.push_back(106);
    a.push_back(244);
    a.push_back(560);
    a.push_back(1286);
    a.push_back(2956);
    a.push_back(6794);
    scanf("%lld",&t);
    while(t--) {
        scanf("%lld",&nnn);
        printf("%lld\n",linear_seq::gao(a,nnn-1));
    }
}

#include <bits/stdc++.h>

using namespace std;
int T;
int n,q;
int v,c;
typedef long long ll;
const ll mod=1e9+7;
ll dp[10005];
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        memset(dp,0,sizeof dp);
        dp[0]=1;
        scanf("%d %d",&n,&q);
        for(int i=1;i<=n;++i)
        {
            scanf("%d %d",&v,&c);
            for(int j=0;j<c;++j)
            {
                int V=v<<j;
                for(int k=10000;k>=V;--k)
                {
                    dp[k]+=dp[k-V];
                    dp[k]%=mod;
                }
            }
        }
        while(q--)
        {
            int x;
            scanf("%d",&x);
            printf("%lld\n",dp[x]);
        }
    }
    return 0;
}

import java.util.Scanner;
import java.math.BigInteger;
public class Main {
    public static void main(String[] args){
        Scanner cin=new Scanner(System.in);
        int T=cin.nextInt();
        for(int i=1;i<=T;i+=1){
            BigInteger S=cin.nextBigInteger();

            BigInteger k1=BigInteger.valueOf(1);

            BigInteger k2=BigInteger.valueOf(2);

            BigInteger k3=S.subtract(k1);

            BigInteger X=S.multiply(k3).divide(k2);

            BigInteger l=k1;
            BigInteger r=S;
            int f1=0;
            for (;;){
                BigInteger sum=l.add(r);
                BigInteger mid=sum.divide(k2);
                BigInteger k=mid.multiply(mid);
                int tmp=k.compareTo(S);
                if (tmp==0){
                    f1=1;
                    break;
                }
                if (tmp>0){
                    r=mid.subtract(k1);
                }
                if (tmp<0){
                    l=mid.add(k1);
                }
                int tmp1=l.compareTo(r);
                if (tmp1>0){
                    break;
                }

            }
            int f2=0;
            l=k1;
            r=X;
            for (;;){
                BigInteger sum=l.add(r);
                BigInteger mid=sum.divide(k2);
                BigInteger k=mid.multiply(mid);
                int tmp=k.compareTo(X);
                if (tmp==0){
                    f2=1;
                    break;
                }
                if (tmp>0){
                    r=mid.subtract(k1);
                }
                if (tmp<0){
                    l=mid.add(k1);
                }
                int tmp1=l.compareTo(r);
                if (tmp1>0){
                    break;
                }
            }

            if(f1==1&&f2==1){
                System.out.println("Arena of Valor");
            }
            if(f1==1&&f2==0){
                System.out.println("Hearth Stone");
            }
            if(f1==0&&f2==1){
                System.out.println("Clash Royale");
            }
            if(f1==0&&f2==0)
            {
                System.out.println("League of Legends");
            }
        }
    }
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
string str;
int a,b,c;
int main() {
    //freopen("1.txt","r",stdin);
    while(scanf("%d%d%d",&a,&b,&c)!=EOF){
        if(a%2==0||b%2==0||c%2==0){
            puts("Yes");
        }
        else puts("No");
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const ll mod=1000000007;
int T;
char str[maxn];
ll fast_pow(ll a,ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1)ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
int main() {
    //freopen("1.txt","r",stdin);
    scanf("%d", &T);
    while (T--) {
        scanf("%s", str);
        int len = strlen(str);
        ll cur = 0;
        for (int i = 0; i <len; i++) {
            cur = (cur * 10 + str[i] - ‘0‘) % (mod - 1);
        }
        cur = (cur - 1 + mod - 1) % (mod - 1);
        cur = fast_pow(2, cur);
        printf("%lld\n", cur);
    }
    return 0;
}

 

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int T;
string str;
int main() {
    //freopen("1.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        cin>>str;
        int len=str.length();
        for (int i=0;i<len;i++){
            if (‘A‘<=str[i]&&str[i]<=‘Z‘){
                str[i]+=32;
            }
        }
        if (str=="jessie"){
            puts("Good guy!");
        }else{
            puts("Dare you say that again?");
        }
    }
    return 0;
}

  

#include<bits/stdc++.h>

using namespace std;
typedef pair<int,int> PI;
const int maxn=5005;
const int M=200005;
const int inf=0x3f3f3f3f;
int a[M];
int n,k,m;
struct Point{
    int x,y,w;
}point[maxn];

struct Min_Cost_Max_Flow
{
    struct edge
    {
        int to,cap,cost,rev;
        edge() {};
        edge(int _to,int _cap,int _cost,int _rev):to(_to),cap(_cap),cost(_cost),rev(_rev) {};
    };
    vector<edge>E[maxn];
    int h[maxn],n,d[maxn],preV[maxn],preE[maxn];
    void init(int n)
    {
        this->n=n;
        for (int i=0; i<=n; i++)
        {
            E[i].clear();
            h[i]=0;
        }
    }
    void add(int from,int to,int cap,int cost)
    {
        E[from].push_back(edge(to,cap,cost,E[to].size()));
        E[to].push_back(edge(from,0,-cost,E[from].size()-1));
    }

    PI dijkstra(int s,int t,int f)
    {
        int cost=0,flow=0;
        for (int i=0; i<=n; i++)
        {
            h[i]=0;
        }
        while (f)
        {
            priority_queue<PI,vector<PI>,greater<PI> >q;
            for (int i=0; i<=n; i++)
            {
                d[i]=inf;
            }
            d[s]=0;
            q.push(make_pair(0,s));
            while (!q.empty())
            {
                PI now=q.top();
                q.pop();
                int v=now.second;
                if (d[v]<now.first)
                {
                    continue;
                }
                for (int i=0; i<E[v].size(); i++)
                {
                    edge &e=E[v][i];
                    if (e.cap>0&&d[e.to]>d[v]+e.cost+h[v]-h[e.to])
                    {
                        d[e.to]=d[v]+e.cost+h[v]-h[e.to];
                        preV[e.to]=v;
                        preE[e.to]=i;
                        q.push(make_pair(d[e.to],e.to));
                    }
                }
            }
            if (d[t]==inf)break;
            for (int i=0; i<=n; i++)
            {
                h[i]+=d[i];
            }
            int d=f;
            for (int i=t; i!=s; i=preV[i])
            {
                d=min(d,E[preV[i]][preE[i]].cap);
            }
            f-=d;
            flow+=d;
            cost+=d*h[t];
            for (int i=t; i!=s; i=preV[i])
            {
                edge &e=E[preV[i]][preE[i]];
                e.cap-=d;
                E[i][e.rev].cap+=d;
            }
        }
        return make_pair(flow,cost);
    }
} G;

int main()
{
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d%d",&n,&k,&m);
        for (int i=1; i<=m; i++)
        {
            scanf("%d%d%d",&point[i].x,&point[i].y,&point[i].w);
            point[i].y++;
        }
        for (int i=1;i<=m;i++){
            a[i]=point[i].x;
            a[i+m]=point[i].y;
        }
        sort(a+1,a+m*2+1);
        int nn=unique(a+1,a+m*2+1)-a-1;
        G.init(nn+2);
        for (int i=1;i<=m;i++){
            point[i].x=lower_bound(a+1,a+1+nn,point[i].x)-a;
            point[i].y=lower_bound(a+1,a+1+nn,point[i].y)-a;
        }
        for (int i=1;i<=nn;i++) {
            G.add(i,i+1,k,0);
        }
        for (int i=1;i<=m;i++) {
            G.add(point[i].x,point[i].y,1,-point[i].w);
        }
        G.add(nn+2,1,k,0);
        PI ans=G.dijkstra(nn+2,nn+1,inf);
        printf("%d\n",-ans.second);
    }
}

原文地址:https://www.cnblogs.com/Accpted/p/11290610.html

时间: 2024-10-04 00:35:40

Contest1828 - 2019年我能变强组队训练赛热身赛的相关文章

Contest1657 - 2019年我能变强组队训练赛第十四场

Contest1657 - 2019年我能变强组队训练赛第十四场 Similarity of Subtrees #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; const int maxn=100100; ull ha[maxn]; vector<int>E[maxn]; unordered_map<ull,int>m;

1780 - 2019年我能变强组队训练赛第十八场

题目描述 wls有一个钟表,当前钟表指向了某一个时间. 又有一些很重要的时刻,wls想要在钟表上复现这些时间(并不需要依次复现).我们可以顺时针转动秒针,也可以逆时针转动秒针,分针和时针都会随着秒针按规则转动,wls想知道秒针至少转动多少角度可以使每个时刻至少都会被访问一次. 注意,时钟上的一种时针分针秒针的组合,可以代表两个不同的时间. 输入 第一行一个整数n代表有多少个时刻要访问. 第二行三个整数h,m,s分别代表当前时刻的时分秒. 最后n行每一行三个整数hi,mi,si代表每个要访问的时刻

Contest1814 - 2019年我能变强组队训练赛第七场

Scores of Final Examination On-Screen Keyboard Tally Counters Balance Scale #pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> using namespace std; typedef long long ll; unordered_map<ll,bool> m1; int n,m,cnt

Contest1539 - 2019年我能变强组队训练赛第十一场

Greater New York 2012 Hailstone HOTPO #pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; int T; cin>>T; while(T--) { ll k; scanf("%lld %lld&q

2019年第二阶段我要变强个人训练赛第十七场

1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const ll mod=1e9+7; 5 const int N=2e6+10; 6 ll c[N],b[N]; 7 ll n,k,a,ans; 8 ll quick(ll a,ll b){ 9 ll res=1; 10 while (b){ 11 if (b&1){ 12 res=res*a%mod; 13 } 14 a=a*a%mo

UPC2018组队训练赛第七场

题目来自ICPC 2017 Japan Tsukuba A题:Secret of Chocolate Poles 有三种巧克力,分别是厚度为1的白色巧克力,厚度为1或者k的黑色巧克力.要求把巧克力放到高度为 l 的盒子里,并且要黑白相间,底部和顶部必须都是黑色的 当l=1,ans=1:当l<k,ans=(l-1)/2+1:当l=k,ans=(l-1)/2+2;当l>k时,就可以转化成排列组合问题了,枚举厚度为k的黑色巧克力数目i,然后对于每一种情况,再枚举厚度为1的黑色巧克力的数目j,那么此时

2016CCPC东北地区大学生程序设计竞赛 (2018年8月22日组队训练赛)

题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016CCPC%B6%AB%B1%B1%B5%D8%C7%F8%B4%F3%D1%A7%C9%FA%B3%CC%D0%F2%C9%E8%BC%C6%BE%BA%C8%FC+-+%D6%D8%CF%D6%C8%FC&source=1&searchmode=source A题题目: 题意: 生成一棵最小生成树,边权值为两个节点的最小公倍数. 思路: 由最小公倍数的和最大公约

2018年第四阶段组队训练赛第三场(BAPC2017 Preliminaries)

D.Disastrous Doubling 题目描述 A scientist, E. Collie, is going to do some experiments with bacteria.Right now, she has one bacterium. She already knows that this species of bacteria doubles itself every hour. Hence, after one hour there will be 2 bacter

第九届福建省大学生程序设计竞赛 2018.8.26组队训练赛

题目链接:http://acm.fzu.edu.cn/contest/list.php?cid=158 A题题目: 题意: 给你六种操作:def, mul,mod,div, add, sub.除了看这几个字母也都知道是啥意思了,其中def是进行define. 思路: 比赛时队友写的,直接模拟,不过赛后补题时队友和我说mul时需要快速乘. 代码实现如下: 1 #include <set> 2 #include <map> 3 #include <queue> 4 #inc