Codeforces Round #260 (Div. 1)

大三目标把codeforces打成黄色以上!

从div1下手,每次做前三道题。

A

一道简单的DP。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<vector>
#define LL long long
#define MAXN 100005
using namespace std;
LL vis[100005];
LL dp[1000005];
int main()
{
    int n;
    scanf("%d",&n);
    int maxi=0;
    for(int i=0; i<n; ++i)
    {
        int a;
        scanf("%d",&a);
        vis[a]+=a;
        maxi=max(maxi,a);
    }
    for(int i=1; i<=maxi; ++i)
        if(i-2>=0)
            dp[i]=max(dp[i-1],dp[i-2]+vis[i]);
        else
            dp[i]=vis[i];
    printf("%I64d\n",dp[maxi]);
    return 0;
}

B

Tire+dp+博弈

win[i]表示当前在i结点时先手是否有胜利可能,lost[i]表示当前在i结点时先手是否有失败可能。

如此可计算出先手是否有胜利和失败可能,然后再进行简单博弈即可。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int n,K;
struct Tire
{
    int ch[100005][26];
    bool win[100005],lost[100005];
    int sz;
    int newnode()
    {
        memset(ch[sz],0,sizeof(ch[sz]));
        win[sz]=lost[sz]=0;
        return sz++;
    }
    void init()
    {
        sz=0;
        newnode();
    }
    int getX(char c)
    {
        return c-‘a‘;
    }
    void insert(char *word)
    {
        int now=0;
        for(int i=0; word[i]; ++i)
        {
            int x=getX(word[i]);
            if(ch[now][x]==0)
                ch[now][x]=newnode();
            now=ch[now][x];
        }
    }
    bool getWin(int now)
    {
        win[now]=false;
        bool noChild=true;
        for(int i=0; i<26; ++i)
        {
            if(ch[now][i])
            {
                noChild=false;
                win[now]|=(!getWin(ch[now][i]));
            }
        }
        if(noChild) return win[now]=false;
        return win[now];
    }
    bool getLost(int now)
    {
        lost[now]=false;
        bool noChild=true;
        for(int i=0; i<26; ++i)
        {
            if(ch[now][i])
            {
                noChild=false;
                lost[now]|=(!getLost(ch[now][i]));
            }
        }
        if(noChild) return lost[now]=true;
        return lost[now];
    }
};
char word[100005];
Tire tree;
int main()
{
    scanf("%d%d",&n,&K);
    tree.init();
    for(int i=1; i<=n; ++i)
    {
        scanf("%s",word);
        tree.insert(word);
    }
    bool firstWin=false,firstLost=false;
    firstWin=tree.getWin(0);
    firstLost=tree.getLost(0);
    if(!firstWin) puts("Second");
    else
    {
        if(firstLost) puts("First");
        else
        {
            if(K&1) puts("First");
            else puts("Second");
        }
    }
    return 0;
}

时间: 2024-08-19 09:43:58

Codeforces Round #260 (Div. 1)的相关文章

Codeforces Round #260 (Div. 2)

A. Laptops 题目意思: 给定n台电脑,第i台电脑的价格是ai ,质量是bi ,问是否存在一台电脑价格比某台电脑价格底,但质量确比某台电脑的质量高,即是否存在ai < aj 且 bi > bj ? 解题思路: 这题一定要看题目,a都是1~n的不同数,b也是1~n的不同数,此题只需要判断ai 是否等于bi ,如果ai != bi 的话,则输出“Happy Alex”,如果所有的ai  == bi 则输出“Poor Alex” 证明:先将a按照从小到大排序,当i<j时ai <

Codeforces Round #260 (Div. 1) A. Boredom (DP)

题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with

dp解Codeforces Round #260 (Div. 2)C. Boredom

#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; lo

递推DP Codeforces Round #260 (Div. 1) A. Boredom

题目传送门 1 /* 2 DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cmath> 7 #include <cstring> 8 using namespace std; 9 10 typedef long long ll; 11 const int MAXN = 1e5 + 10; 12 const int INF

Codeforces Round #260 (Div. 2) A. Laptops(简单题)

题目链接:http://codeforces.com/problemset/problem/456/A A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Dima and Alex had an argument about the price and quality of laptops.

Codeforces Round #260 (Div. 2) B. Fedya and Maths(循环节)

题目链接:http://codeforces.com/problemset/problem/456/B B. Fedya and Maths time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Fedya studies in a gymnasium. Fedya's maths hometask is to calculate t

DP Codeforces Round #260 (Div. 1) A. Boredom

题目传送门 1 /* 2 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 3 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) i * cnt[i]); 4 只和x-1,x-2有关,和顺序无关,x-1不取,x-2取那么累加相同的值,ans = dp[mx] 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring&

Codeforces Round #260 (Div. 2) ABCDE

A题逗比了,没有看到All ai are distinct. All bi are distinct. 其实很水的.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 #define mnx 100002 8 9 10 struct latop{ 11 int p, q; 12 bo

Codeforces Round #260 (Div. 1)——Civilization

题目链接 题意: n个点,m条边的森林,q次操作.每次操作:1.询问x所在树的直径 2.合并x和y所在的树,使得合并后的直径最小 (1?≤?n?≤?3·105; 0?≤?m?<?n; 1?≤?q?≤?3·105) 分析: 没有读到图是森林...做的好纠结 最开始将每个树都求一下直径,之后使用并查集处理,每次合并直径:至少是两个树的直径,或者将两个直径的最中间的部分连接求直径 const int MAXN = 310000; int rt[MAXN], ans[MAXN]; VI G[MAXN];