Codeforces 274 Div2

A

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
int main()
{
    int a,b,c;
    while (cin>>a>>b>>c)
    {
        int src[100];
        src[0] = a + b * c;
        src[1] = a * b * c;
        src[2] = (a + b) * c;
        src[3] = a * b + c;
        src[4] = a * (b + c);
        src[5] = a + b + c;
        sort(src,src+6);
        printf("%d\n",src[5]);
    }
    return 0;
}

B

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
int N,K;
#define MAXN 120
struct node
{
    int id,val;
    friend bool operator < (const node & a,const node &b)
    {
        return a.val < b.val;
    }
}src[MAXN];
priority_queue<node>q;
node res[120];
int x[1010],y[1010];
int main()
{
    while (scanf("%d%d",&N,&K) != EOF)
    {
        int l = 100000,r = 0;
        for (int i = 0 ;i < N ;i++)
        {
            scanf("%d",&src[i].val);
            src[i].id = i + 1;
            l = min(l,src[i].val);
            r = max(r,src[i].val);
            q.push(src[i]);
        }
        if (l == r) {puts("0 0");continue;}
        node u,s;
        int cur ,pre = 250000;
        int anscnt = 0;

        for (int i = 1; i <= K; i++)
        {
            if (cur == 0) break;
            l = 100000;
            r = 0;
            u = q.top();q.pop();int cas = 0;
            res[cas++] = u;
            while (true)
            {
                s = q.top();q.pop();
                res[cas++] = s;
                if (q.empty()) break;
            }
            //for (int i = 0 ;i < cas; i++) printf("%d %d\n",res[i].val,res[i].id);puts("");
            res[0].val--;
            res[cas - 1].val++;
            anscnt++;
            x[anscnt] = res[0].id;
            y[anscnt] = res[cas - 1].id;
            for (int i = 0 ; i < cas; i++)
            {
                q.push(res[i]);
                l = min(l,res[i].val);
                r = max(r,res[i].val);
            }
            cur = r - l;
        }
        printf("%d %d\n",cur,anscnt);
        for (int i = 1; i <= anscnt; i++) printf("%d %d\n",x[i],y[i]);
    }
    return 0;
}

C

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
#define MAXN 5005
int N;
struct node
{
    int a,b;
    friend bool operator < (const node & s,const node & t)
    {
        if (s.a == t.a) return s.b < t.b;
        return s.a < t.a;
    }
}src[MAXN];
int cmp(const node &s,const node &t)
{
    return  s.b < t.b;
}
int main()
{
    scanf("%d",&N);
    for (int i = 0;i < N ;i++) scanf("%d%d",&src[i].a,&src[i].b);
    sort(src,src + N);
    //for (int i = 0 ;i < N; i++) printf("%d %d \n",src[i].a,src[i].b);
    bool flag = true;
    for (int i = 1; i < N; i++) if (src[i].b < src[i-1].b) {flag = false ; break;}
    if (flag) { printf("%d\n",src[N - 1].b);return 0;}
    printf("%d\n",src[N - 1].a);
    return 0;
}

D

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
int t[1000005];
set<int>s;
int main()
{
    int N,L,x,y;
    cin >> N >> L >> x >> y;
    bool fx = false , fy = false;
    for (int i = 1; i <= N; i++)
    {
        cin >> t[i];
        s.insert(t[i]);
    }
    for (int i = 1; i <= N; i++)
    {
        if (s.find(t[i] + x) != s.end()) fx = true;
        if (s.find(t[i] + y) != s.end()) fy = true;
    }
    if (fx && fy) { puts("0");return 0;}
    if (fx)
    {
        printf("1\n");
        printf("%d\n",y);
        return 0;
    }
    if (fy)
    {
        printf("1\n");
        printf("%d\n",x);
        return 0;
    }
    for (int i = 1; i <= N; i++)
    {
        if (t[i] + x <= L && ( s.find(t[i] + x + y) != s.end() || (s.find(t[i] + x - y) != s.end())))
        {
            printf("1\n");
            printf("%d\n",t[i] + x);
            return 0;
        }
        if (t[i] - x >= 0 && (s.find(t[i] - x + y) != s.end() || s.find(t[i] - x - y) != s.end()))
        {
            printf("1\n");
            printf("%d\n",t[i] - x);
            return 0;
        }
    }
    printf("2\n%d %d\n",x,y);
    return 0;
}

E

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
#define MAXN 5010
#define MOD 1000000007
LL dp[2][MAXN],sum[2][MAXN];
int N,A,B,K;
int main()
{
    while (scanf("%d%d%d%d",&N,&A,&B,&K) != EOF)
    {
        memset(dp,0,sizeof(dp));
        memset(sum,0,sizeof(sum));
        dp[0][A] = 1;
        for (int i = A; i <= N; i++) sum[0][i] = 1;
        int now = 0;
        for (int i = 1; i <= K; i++)
        {
            now ^= 1;
            memset(dp[now],0,sizeof(dp[now]));
            memset(sum[now],0,sizeof(sum[now]));
            for (int j = 1; j <= N; j++)
            {
                if (j < B)
                {
                    if ((j + B) % 2 == 0)
                    {
                        int k = (j + B) / 2 - 1;
                        dp[now][j] = (dp[now][j] + sum[now ^ 1][k] - dp[now ^ 1][j]) % MOD;
                    }
                    else
                    {
                        int k = (j + B) / 2;
                        dp[now][j] = (dp[now][j] + sum[now ^ 1][k] - dp[now ^ 1][j]) % MOD;
                    }
                }
                else if (j > B)
                {
                    if ((j + B) % 2 == 0)
                    {
                        int k =(j + B) / 2 + 1;
                        dp[now][j] = (dp[now][j] + sum[now ^ 1][N] - sum[now ^ 1][k - 1] -dp[now ^ 1][j]) % MOD;
                    }
                    else
                    {
                        int k = (j + B) / 2 + 1;
                        dp[now][j] = (dp[now][j] + sum[now ^ 1][N] - sum[now ^ 1][k - 1] -dp[now ^ 1][j]) % MOD;
                    }
                }
                sum[now][j] = (sum[now][j - 1] + dp[now][j]) % MOD;
            }
        }
        LL ans = 0;
        for (int i = 1; i <= N; i++)
            ans = (ans + dp[now][i]) % MOD;
        printf("%I64d\n",(ans + MOD) % MOD);
    }
    return 0;
}

时间: 2024-08-28 06:59:25

Codeforces 274 Div2的相关文章

Codeforces 583 DIV2 Robot&#39;s Task 贪心

原题链接:http://codeforces.com/problemset/problem/583/B 题意: 就..要打开一个电脑,必须至少先打开其他若干电脑,每次转向有个花费,让你设计一个序列,使得总花费最小. 题解: 就傻傻的走就好..从左走到右,再走回来,更新序列和答案就好. 代码: #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #define MA

Codeforces #180 div2 C Parity Game

// Codeforces #180 div2 C Parity Game // // 这道题的题目意思就不解释了 // // 题目有那么一点难(对于我而言),不多说啦 // // 解题思路: // // 首先如果a串和b串相等,不多说直接YES // 如果b串全是0,直接YES // 注意到a串有一个性质,1的个数不会超过本身的加1. // a有个1的上限设为x,b有个1的个数设为y,则如果x < y // 那么直接NO. // // 现在一般情况下,就是模拟啦,找到a的后缀和b的前缀一样的

Codeforces #246(div2)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <ti

Codeforces #245(div2)

A:A. Points and Segments (easy) 题目看了n久,开始觉得尼玛这是div2的题目么,题目还标明了easy.. 意思是给你一n个点,m个区间,在n个点上放蓝球或者红球,然后让你找一种选择方案使得m个区间内的蓝球和红球数量之差不超过1. 开始想过用dfs,不过这只是div2的A题而已.. 然后想了下,直接输出010101序列不就可以么. 交了一发,发现要先排个序,再输出就可以了. AC代码: #include<iostream> #include<cstdio&g

codeforces#327 div2

codeforces#327 div2 这场状态不好有点可惜,题目都不难,而且很好.. A题:水题. #include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; typedef lo

codeforces#FF(div2) DZY Loves Sequences

n个数,可以任意改变其中一个数,求最长的上升子区间长度 思路:记录一个from[i]表示从位置i的数开始最长的上升区间长度 记录一个to[i]表示到位置i的数所能达到的最长上升区间长度 枚举要改变的数的位置i,此时能达到的长度为to[i - 1] + from[i + 1] + 1,取最大值 //#pragma comment(linker, "/STACK:102400000,102400000") //HEAD #include <cstdio> #include &l

Codeforces 258 Div2

A题,n*m根木棍,相交放置,轮流取走相交的两根,最后谁不能行动,则输掉. min(n,m)&1 为1则先取者赢. B题,给定一个长度为n,且各不相同的数组,问能否通过交换连续一段L....R使得变成单调递增. 如果一开始就是递增的,那么直接输出L...R就是1 1,交换一个就行了:否则判断中间是否有且一段单调递减,且两端交换后使得数组递增. 代码: 1 //Template updates date: 20140718 2 #include <iostream> 3 #include

Codeforces #263 div2 解题报告

比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注册的时候很想好好的做一下,但是网上喝了个小酒之后,也就迷迷糊糊地看了题目,做了几题,一觉醒来发现rating掉了很多,那个心痛啊! 不过,后来认真的读了题目,发现这次的div2并不是很难! 官方题解:http://codeforces.com/blog/entry/13568 A. Appleman and Easy Task 解析: 一个水题,判断每个细胞周围是否都是有偶数个相邻细胞.   代码

codeforces#333 div2 B. Approximating a Constant Range

http://codeforces.com/contest/602/problem/B 这道题的两种做法, 滑窗+线段树查询区间最值: #include<bits/stdc++.h> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) using namespace std; typedef long long ll; const int maxn=1000100; const int