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

2013.21.A

时间:2014-06-07 23:47:15      阅读:497      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   a   

随便点了一套刷,这套质量挺棒的,学了不少的东西,并且碰到了很久都没有打的题目

//很久没有刷一套题了吧,最近发生的东西实在可怕到我都难以接受了....clam down clam dowm 先管好自己的事再说吧~

1.card

  

很久没有感受指针的题目了...打起来确实很陌生了

先说一下思路吧,大概是这样的根据队列的思想,设有h,w两个头尾指针

边读边处理,如果头元素在这个队列里出现了2次,那么就把它清除,即h++;

以及判断所有的数是否全都在队列里面,找到最优的值

主要部分是这样的
for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        t++;b[a[i]]++;
        s=s+w[a[i]];
        if(b[a[i]]==1) l++;
        while(b[a[h]]>1){
            b[a[h]]--;
            s-=w[a[h]];
            h++;
        }
        if(l==m){
            if(s<ans) ans=s;
        }
    }
  2.line

  

 
之前曾在usaco里看到一道类似的题目,不过那是没有考虑这么多,两个for过去,貌似当时也没有超时...
但是这里明显是不行的

=-=然后就默默地偷瞥了眼题解,看到那个图顿时有一种恍然大悟的感觉!...做法很巧妙
bubuko.com,布布扣

用f,g两个数组分别记录头和尾

然后 s+=h[i];
if(s>0) ans++;
s-=g[i];
很棒的想法是不是?是~

主代码
for(int i=0;i<n;i++){
    scanf("%d%d",&x,&y);
    h[x]++;
    w[y]++;
}
for(int i=0;i<m;i++){
    s+=h[i];
    if(s>0) t++;
    s-=w[i];
}
 3. rectangle
  高精=-=表示真的真的很久很久没有打了!!
学长友情教我打了一个模板~跪跪跪~
自己mark一下


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct hugeint{
    int l,s[300];
    hugeint () {
        l = 1; memset (s, 0, sizeof (0));
    }
    bool operator <(const hugeint & a)const{
        if(l!=a.l)return l<a.l;
        for(int i=a.l;i;i--)
            if (a.s[i]!=s[i]) return s[i]<a.s[i];
        return 0;
    }
    hugeint operator*(const hugeint &a){
        hugeint c;
        for(int i=1;i<=l;i++)
           for(int j=1;j<=a.l;j++){
               c.s[i+j-1]+=s[i]*a.s[j];
               c.s[i+j]+=c.s[i+j-1]/10;
               c.s[i+j-1]%=10;
           }
        c.l = l+a.l;
        while (c.l > 1 && !c.s[c.l]) c.l--;
        return c;
    }
    hugeint operator+(const hugeint &a){
        hugeint c;
        for(int i=1;i<=max(a.l,l);i++){
            c.s[i]+=a.s[i]+s[i];
            c.s[i+1]+=c.s[i]/10;
            c.s[i]%=10;
        }
        c.l=max(a.l+1,l+1);
        while (c.l > 1 && !c.s[c.l]) c.l--;
        return c;
    }
    hugeint operator-(const hugeint &a){
        hugeint c;
        for(int i=1;i<=max(a.l,l);i++){
            c.s[i]+=s[i]-a.s[i];
            if(c.s[i]<0) c.s[i]+=10, c.s[i+1]--;
        }
        c.l=l;
        while (c.l > 1 && !c.s[c.l]) c.l--;
        return c;
    }
    hugeint operator/(const int &a){
        hugeint c;
        for(int i=l;i>=1;i--){
            c.s[i]=s[i]/4;
            if(c.s[i]!=0){
                c.s[i+1]+=c.s[i]%4;
                c.s[i]/=4;
            }
        }
        c.l=l;
        while (c.l > 1 && !c.s[c.l]) c.l--;
        return c;
    }
     
};
hugeint into(){
    char s[300];
    scanf("%s",s);
    hugeint c;
    c.l = strlen (s);
    for (int i=0; i<c.l; i++)
        c.s[i] = s[c.l-i+1]-‘0‘;
    return c;
}
int main(){
    freopen("rectangle.in","r",stdin);
    freopen("rectangle.out","w",stdout);
    hugeint n1,m1,n2,m2,n,m,a,b;
    n1=into();
    m1=into();
    n2=into();
    m2=into();
    hugeint one;
    one.s[1]=1;
    a=n1*(n1+one)*m1*(m1+one)/4;
    b=n2*(n2+one)*m2*(m2+one)/4;
    n=min(n1,n2);
    m=min(m1,m2);
    n=n*(n+one)*m*(m+one)/4;
    printf("%lld",a+b-n);
    return 0;
}

  哦对了,以及矩形个数要记得(n+1)*n*(m+1)*m/4;





 

2013.21.A,布布扣,bubuko.com

2013.21.A

标签:c   style   class   blog   code   a   

原文地址:http://www.cnblogs.com/polebug/p/3774610.html

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