多第八田間學校:幾何+圖論出度+類比+找到規律

來源:互聯網
上載者:User

標籤:

HDU 4946 

pid=1002&cid=509" style="color:rgb(26,92,200); text-decoration:none; font-family:Tahoma; background-color:rgb(215,235,255)">Area of Mushroom

這題WA了7發才過,隊友做的,然後一起debug了好久。

剛開始是沒排序。

然後是在同一個位置的點沒有處理好。

然後把這兩個問題搞定就A了。

#include <algorithm>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#include <ctype.h>#include <iostream>#include <map>#include <queue>#include <set>#include <stack>#include <string>#include <vector>#define eps 1e-10#define INF 0x7fffffff#define maxn 10005#define PI acos(-1.0)#define seed 31//131,1313typedef long long LL;typedef unsigned long long ULL;using namespace std;int x[505],y[505],v[505],vis[505];int cmp(double x){    if(fabs(x)<eps)        return 0;    if(x>0)        return 1;    return -1;}inline double sqr(double x){    return x*x;}struct point//點{    double x,y;    int pos;    int o;    point() {}    point(double a,double b):x(a),y(b) {}    void input()    {        scanf("%lf%lf",&x,&y);    }    friend point operator + (const point &a,const point &b)    {        return point(a.x+b.x,a.y+b.y);    }    friend point operator - (const point &a,const point &b)    {        return point(a.x-b.x,a.y-b.y);    }    friend bool operator == (const point &a,const point &b)    {        return cmp(a.x-b.x)==0 &&cmp(a.y-b.y)==0;    }    friend point operator * (const point &a,const double &b)    {        return point(a.x*b,a.y*b);    }    friend point operator * (const double &a,const point &b)    {        return point(a*b.x,a*b.y);    }    friend point operator / (const point &a,const double &b)    {        return point(a.x/b,a.y/b);    }    double norm()    {        return sqrt(sqr(x)+sqr(y));    }//到原點距離    void out () const    {        printf("%.2f %.2f",x,y);    }} p[505];double det (const point &a,const point &b){    return a.x*b.y-a.y*b.x;}//叉積double dot (const point &a,const point &b){    return a.x*b.x+a.y*b.y;}//點乘double dist (const point &a,const point &b){    return (a-b).norm();}//距離point rotate_point(const point &p,double A){    double tx=p.x,ty=p.y;    return point (tx*cos(A)-ty*sin(A),tx*sin(A)+ty*cos(A));}//旋轉,A是弧度struct polygon_convex{    vector <point> P;    polygon_convex(int size=0)    {        P.resize(size);    }} p_c;bool comp_less(const point &a,const point &b){    return cmp(a.x-b.x)<0||cmp(a.x-b.x)==0&&cmp(a.y-b.y)<0;}polygon_convex convex_hull(vector <point> a){    polygon_convex res(2*a.size()+5);    sort(a.begin(),a.end(),comp_less);    a.erase(unique(a.begin(),a.end()),a.end());    int m=0;    for(int i=0; i<a.size(); i++)    {        while(m>1 && cmp(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<0)            m--;        res.P[m++]=a[i];    }    int k=m;    for(int i=int(a.size())-2; i>=0; i--)    {        while(m>k && cmp(det(res.P[m-1]-res.P[m-2],a[i]-res.P[m-2]))<0)            m--;        res.P[m++]=a[i];    }    res.P.resize(m);    if(a.size()>1)        res.P.resize(m-1);    return res;}bool cmp3(point a,point b){    return a.x<b.x||((a.x==b.x)&&(a.y<b.y));}int main(){    int T,tt=0;    while(scanf("%d",&T))    {        tt++;        vector<point>pp;        pp.clear();        memset(vis,0,sizeof(vis));        if(T==0)            break;        int pos=-1;        int max_v=0;        for(int i=1; i<=T; i++)        {            scanf("%d%d%d",&x[i],&y[i],&v[i]);            if(v[i]>max_v)                max_v=v[i];        }        int top=0;        for(int i=1; i<=T; i++)        {            if(v[i]==max_v)            {                p[top].x=(double)x[i];                p[top].y=(double)y[i];                p[top].pos=i;                p[top].o=0;                top++;            }        }        printf("Case #%d: ",tt);        if(max_v==0)        {            for(int i=1; i<=T; i++)                printf("0");            printf("\n");            continue;        }        sort(p,p+top,cmp3);        for(int i=0; i<top; i++)        {            if((i<top-1&&(p[i].x)==(p[i+1].x)&&(p[i].y)==(p[i+1].y))||(i>0&&(p[i].x)==(p[i-1].x)&&(p[i].y)==(p[i-1].y)))                p[i].o=1;        }        pp.push_back(p[0]);        for(int i=1; i<top; i++)        {            if(p[i].x!=p[i-1].x||p[i].y!=p[i-1].y)                pp.push_back(p[i]);        }        if(pp.size()<=3)        {            for(int i=0; i<pp.size(); i++)                if(pp[i].o==0)                    vis[pp[i].pos]=1;        }        else        {            polygon_convex ans=convex_hull(pp);            for(int i=0; i<ans.P.size(); i++)            {                //cout<<ans.P[i].ok<<" "<<ans.P[i].pos<<endl;                if(ans.P[i].o==0)                    vis[ans.P[i].pos]=1;            }        }        for(int i=1; i<=T; i++)            printf("%d",vis[i]);        printf("\n");    }    return 0;}/*32 2 32 2 32 3 361 1 31 -1 32 0 3-1 1 3-1 -1 3-2 0 341 1 11 2 11 3 11 4 1151 1 01 1 12 1 13 1 14 1 15 1 15 2 15 3 15 4 14 4 13 4 12 4 11 4 11 3 11 2 191 4 11 3 11 2 11 1 12 1 13 1 14 1 13 2 12 3 1*/



HDU 4948 Kingdom

這題比賽的時候遺憾了。我看了這道題。然後認為挺簡單的。

剛開始一看題上,想到的就是拓撲排序。然後腦子想啊想……感覺就是拓撲排序的逆序。然後發現挺水的……

由於說了要想發展某個城市的話,就必須有還有一個城市作為它發展的前提,即城市u->w這樣連邊,表示要想發展城市w,前提是u已經是發展過的城市了。那這種話不是非常easy嘛。

即統計出出度最多的就是第一個要發展的城市了。由於u->w這樣連邊能夠看出算出出度最多的依次從大到小排序即可了。

哎呀。只是可惜了。由於看見沒人交這題。然後也不敢把自己想的告訴隊友,然後自己也沒敲……然後錯過進第一版的機會了真是被第一梯隊的帶錯路被坑了……

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<cmath>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define llson j<<1,l,mid#define rrson j<<1|1,mid+1,r#define INF 0x7fffffff#define maxn 11010using namespace std;typedef long long ll;typedef unsigned long long ull;char s[500][505];struct abc{    int i,out;    bool operator<(const abc &a)const    {        return out>a.out;    }}a[501];int main(){    //freopen("1.txt","r",stdin);    int n,i,j;    while(scanf("%d",&n)&&n)    {        for(i=0;i<n;i++)            scanf("%s",s[i]),a[i].i=i,a[i].out=0;        for(i=0;i<n;i++)            for(j=0;j<n;j++)                if(s[i][j]=='1')                    a[i].out++;        sort(a,a+n);        printf("%d",a[0].i+1);        for(i=1;i<n;i++)            printf(" %d",a[i].i+1);        puts("");    }    return 0;}

HDU 4951 Multiplication table

乘法表。

看每行。兩個數都相等的就是0了。

然後看第一位不相等的個數,多少個不同就是哪個數了。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<cmath>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define llson j<<1,l,mid#define rrson j<<1|1,mid+1,r#define INF 0x7fffffff#define maxn 11010using namespace std;typedef long long ll;typedef unsigned long long ull;int a[511][1011],vis[511];int main(){    //freopen("1.txt","r",stdin);    int n,i,j,ii=1;    while(scanf("%d",&n)&&n)    {        int flag,b[512];        for(i=0; i<n; i++)        {            for(j=0,flag=0; j<n; j++)            {                scanf("%d%d",&a[i][j<<1],&a[i][j<<1|1]);                if(a[i][j<<1]!=a[i][j<<1|1]) flag++;            }            if(!flag) b[0]=i;        }        for(i=0;i<n;i++)        {            if(i==b[0]) continue;            mem(vis,0);            int sum=0;            for(j=0;j<(n<<1);j+=2)                if(!vis[a[i][j]]) sum++,vis[a[i][j]]=1;            b[sum]=i;        }        printf("Case #%d: %d",ii++,b[0]);        for(i=1;i<n;i++)            printf(" %d",b[i]);        puts("");    }    return 0;}

HDU 4952 

pid=1008&cid=509" style="color:rgb(26,92,200); text-decoration:none; font-family:Tahoma; background-color:rgb(215,235,255)">Number Transformation

這題規律題,輸出前面100個值與倍數就會發現往後的倍數都是一樣的了,倍數一樣就是每次都加同樣的數到最後,這種話就變成簡單的乘法了。

代碼中凝視的三句就是用來找規律的。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<cmath>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define INF 10000010#define maxn 80010using namespace std;typedef long long ll;typedef unsigned long long ull;int main(){    ll n,m;    int ans=1;    while(scanf("%I64d%I64d",&n,&m)&&(n||m))    {        //int cnt=0;        ll a=-1,b=-1,sum=0,i;        int flag=0;        for(i=2LL;i<=m;i++)        {            if(n%i)            {                b=n/i+1LL;                n=b*i;                //if(cnt++<100)                //cout<<"+++ "<<n<<' '<<(int)(n/i)<<' '<<i<<endl;                if(b==a) break;                else a=b;                flag=1;            }        }        if(flag&&i<m)        {            sum=m-i;            sum=sum*a+n;        }        else sum=n;        printf("Case #%d: %I64d\n",ans++,sum);    }    return 0;}



多第八田間學校:幾何+圖論出度+類比+找到規律

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.