Codeforces Round #291 Div2

A. Chewbaсca and Number

签到题

//#pragma comment(linker, "/STACK:102400000,102400000") 手动扩栈
#include<iostream>
#include<algorithm>
#include <queue>
#include<stack>
#include<map>
#include<string>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define N 100
char s[N];
int main()
{
    int n,m;
    cin>>s;
    int len = strlen(s);
    for(int i=0;i<len;i++)
    {
        if(i==0&&s[i]=='9') continue;
        if(s[i] > '9'-s[i]+'0') s[i]='9'-s[i]+'0';
        //printf("%c %c\n",s[i],)
    }
    cout<<s<<endl;
    return 0;
}

B. Han Solo and Lazer Gun

注意精度

#include<iostream>
#include<algorithm>
#include <queue>
#include<stack>
#include<map>
#include<string>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define orz printf("orz...\n");
#define eps 1e-6
#define PI acos(-1.0)
#define N 1000+10
set<int> s;
set<int> de;
set<int>::iterator it;
double x[N],y[N];
int cmp(double x)
{
    if(  fabs(x) < eps) return 1;
    return 0;
}
int main()
{
    int n;
    double tx,ty;
    double ttx,tty;
    s.clear();
    cin>>n>>x[0]>>y[0];
    for(int i=1;i<=n;i++){
        scanf("%lf%lf",&x[i],&y[i]);
        s.insert(i);
    }
    int ans= 0 ;
    while(!s.empty())
    {
        de.clear();
        it = s.begin();
        ans++;
        tx = x[*it]; ty = y[*it];
        for(;it!=s.end();it++)
        {
            ttx = x[*it]; tty=y[*it];
            if(cmp( (ty-y[0])*(ttx-tx)-(tty-ty)*(tx-x[0]) ) )
               de.insert(*it);
        }
        for(it=de.begin();it!=de.end();it++)
            s.erase(*it);
    }
    cout<<ans<<endl;

    return 0;
}

C. Watto and Mechanism

Trie树
+ dfs搜索

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N = 6*100000+10;
const int maxnode = 6*100000+10;
const int sigma_size = 4;
int len;
char s[N];
struct Trie
{
    int ch[maxnode][sigma_size];
    int val[maxnode];
    int sz;
    Trie() {sz=1;memset(ch[0],0,sizeof(ch[0])); }
    int idx(char x) {return x-'a';}

    void insert(char *s,int v) // v is the value of s
    {
        int u = 0,n = strlen(s);
        for(int i=0;i<n;i++)
        {
            int c = idx(s[i]);
            if(!ch[u][c])
            {
                memset(ch[sz],0,sizeof(ch[sz]));
                val[sz] = 0;
                ch[u][c] = sz++;
            }
            u = ch[u][c];
        }
        val[u] = v;
    }
};
Trie t;
int dfs(char *s,int u,int id,int f)
{
    if(id==len)
    {
        if(f==1 && t.val[u]) return 1;
        return 0;
    }
    //cout<<id<<" f="<<f<<"\n";
    int c = t.idx(s[id]);
    int c1 = (c+1)%3;
    int c2 = (c+2)%3;
    //cout<<"i'm checking "<<c<<" "<<t.ch[u][c]<<endl;
    if(t.ch[u][c] && dfs(s,t.ch[u][c],id+1,f)) return 1;
    if(t.ch[u][c1] && f==0 && dfs(s,t.ch[u][c1],id+1,1) ) return 1;
    if(t.ch[u][c2] && f==0 && dfs(s,t.ch[u][c2],id+1,1) ) return 1;
    //cout<<"over in "<<id<<endl;
    return 0;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        t.insert(s,1);
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%s",s);
        len = strlen(s);
        if( dfs(s,0,0,0)==1 ) puts("YES");
        else puts("NO");
    }
    return 0;
}

D. R2D2 and Droid Army

RMQ_ST
+ 维护一个连续区间(队列)

//#pragma comment(linker, "/STACK:102400000,102400000") 手动扩栈
#include<iostream>
#include<algorithm>
#include <queue>
#include<stack>
#include<map>
#include<string>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define INF 2000000002
#define pow(a,b,c,d) (a-c)*(a-c)+(b-d)*(b-d)
#define swap(a,b) (a^=b,b^=a,a^=b)
#define sca(a) scanf("%d",&a)
#define mem(a) memset(a,0,sizeof(a))
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define orz printf("orz...\n");
#define eps 1e-8
#define PI acos(-1.0)
//求区间最值问题(原数值不改变)
const int N = 100000+10;
const int M = 100 ;
int n,m;
int a[6][N];
int dp[6][N][M]; // dp[i][j] 为从 i 开始 ,长度为 2^j 的区间内 最值
long long ans[6];
void RMQ_init()
{
    for(int k=1;k<=m;k++){
    for(int i=1;i<=n;i++) dp[k][i][0] = a[k][i];
    for(int j=1;(1<<j)<=n;j++)
        for(int i=1; i+(1<<j)-1<=n ;i++)
            dp[k][i][j] = max(dp[k][i][j-1],dp[k][i+(1<<(j-1))][j-1]);
    }
}
int RMQ_ST(int kk,int l,int r)
{
    int k = 0;
    while( (1<<(k+1)) <= r-l+1 ) k++;
    return max(dp[kk][l][k],dp[kk][r-(1<<k)+1][k]);
}
int main()
{
    long long k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[j][i]);
    RMQ_init();
    int l=1,r=1;
    int sans=-1;
    memset(ans,0,sizeof(ans));
    while(r<=n)
    {
        int sum=0;
        for(int i=1;i<=m;i++){
            sum+=RMQ_ST(i,l,r);
        }
        if(sum > k){
            l++;
            while(r<l) r++;
        }
        else{
            if(r-l+1 >= sans){
                for(int i=1;i<=m;i++)
                    ans[i]=RMQ_ST(i,l,r);
                sans = max(sans,r-l+1);
            }
            r++;
        }
    }
    int ss=0;
    for(int i=1;i<=m-1;i++){
        cout<<ans[i]<<" ";
        ss+=ans[i];
    }
    cout<<ans[m];
    cout<<endl;
    return 0;
}
时间: 2024-10-12 19:32:30

Codeforces Round #291 Div2的相关文章

Codeforces Round #291 Div2 C

Problem 给N个字符串Si,进行M次询问,每次给定一个字符串S,问是否存在一个Si使得S与Si长度相等,同时有且只有一个字符不同. Limits TimeLimit(ms):3000 MemoryLimit(MB):256 N,M∈[0,3×105] 所有串总长不超过6×105 Look up Original Problem From here Solution 字典树才是正解,但用hash会很方便. 双hash,seed=1e4级别的素数,mod1=1e9+7,mod2=1e9+9 C

Codeforces Round #291 Div2 D

Problem An army of n droids is lined up in one row. Each droid is described by m integers a1,?a2,?...,?am, where ai is the number of details of the i-th type in this droid's mechanism. R2?D2 wants to destroy the sequence of consecutive droids of maxi

codeforces round #257 div2 C、D

本来应该认真做这场的,思路都是正确的. C题,是先该横切完或竖切完,无法满足刀数要求,再考虑横切+竖切(竖切+横切), 因为横切+竖切(或竖切+横切)会对切割的东西产生交叉份数,从而最小的部分不会尽可能的大. 代码如下,虽然比较长.比较乱,但完全可以压缩到几行,因为几乎是4小块重复的代码,自己也懒得压缩 注意一点,比如要判断最小块的时候,比如9行要分成2份,最小的剩下那份不是9取模2,而应该是4 m/(k+1)<=m-m/(k+1)*k          #include<bits/stdc+

codeforces Round #250 (div2)

a题,就不说了吧 b题,直接从大到小排序1-limit的所有数的lowbit,再从大到小贪心组成sum就行了 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #define N 200000 6 using namespace std; 7 int pos[N],a[N],s[N],f[N],la[N],b[N],i,j,k,ans,n,p

Codeforces Round#320 Div2 解题报告

Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Finding Team Member codeforces 579C A Problem about Polyline codeforces 579D "Or" Game codeforces 579E Weakness and Poorness codeforces 579F LCS Aga

Codeforces Round #254(div2)A

很有趣的题.想到了就非常简单,想不到就麻烦了. 其实就是一种逆向思维:最后结果肯定是这样子: WBWBWBWB... BWBWBWBW... WBWBWBWB... ... 里面有“-”的地方改成“-”就行了. 但是我开始是正着想的,想每个点怎么处理,这还要看它周围点的状态,越想越麻烦... 这题中体现的正难则反的逆向思维很值得学习. #include<iostream> #include<cstdio> #include<cstdlib> #include<cs

Codeforces Round #254(div2)B

就是看无向图有几个连通块,答案就是2n-num. 范围很小,就用矩阵来存图减少代码量. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm> #inc

Codeforces Round #260(div2)C(递推)

有明显的递推关系: f[i]表示i为数列中最大值时所求结果.num[i]表示数i在数列中出现了几次. 对于数i,要么删i,要么删i-1,只有这两种情况,且子问题还是一样的思路.那么很显然递推一下就行了:f[i]=max(f[i-1],f[i-2]+i*num[i]); 这里技巧在于:为了防止麻烦,干脆就所有数的出现次数都记录一下,然后直接从2推到100000(类似于下标排序),就不用排序了,也不用模拟删除操作了.这一技巧貌似简单,但实际上临场想出来也需要点水平. #include<iostrea

Codeforces Round #289 Div2 E

Problem 给一串长度为N的字符串,对于每个字符,若字符为元音,则权值为1,否则为0.一个子串的权值定义为该串所有字符权值之和除以字符个数,一个母串的权值定义为所有子串的权值之和.求母串的权值. Limits Time Limit(ms): 1000 Memory Limit(MB): 256 N: [1, 5*10^5] 字符集: 'A'-'Z' 元音: I E A O U Y Solution 考虑每个元音字符对母串的贡献,可以找出规律. More 举"ABCDOEFGHKMN"