codeForces #140 div 2

來源:互聯網
上載者:User

第一題弱逼了,線代沒好好學,忘了叉積可以判斷兩個向量的方向:

叉乘(cross product)
相對於點乘,叉乘可能更有用吧。2維空間中的叉乘是:
    V1(x1,
y1) X V2(x2, y2) = x1y2 – y1x2
看起來像個標量,事實上叉乘的結果是個向量,方向在z軸上。上述結果是它的模。在二維空間裡,讓我們暫時忽略它的方向,將結果看成一個向量,那麼這個結果類似於上述的點積,我們有:
    A
x B = |A||B|Sin(θ)
然而角度 θ和上面點乘的角度有一點點不同,他是有正負的,是指從A到B的角度。中 θ為負。
另外還有一個有用的特徵那就是叉積的絕對值就是A和B為兩邊說形成的平行四邊形的面積。也就是AB所包圍三角形面積的兩倍。在計算面積時,我們要經常用到叉積。
(譯註:三維及以上的叉乘參看維基:http://en.wikipedia.org/wiki/Cross_product)

/*Problem ID:meaning:Analyzing:*/#include <iostream>#include <algorithm>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<vector>using namespace std;typedef struct even{int y1,y2,x;}even;#define clr(A,k) memset(A,k,sizeof(A))#define FOR(i,s,t) for(int i=(s); i<(t); i++)#define LL long long#define BUG puts("here!!!")#define print(x) printf("%d\n",x)#define STOP system("pause")#define eps 1e-8#define PI acos(-1.0)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define maxn 16666#define maxm 1005#define MOD  1000000007#define lowbit(x) x&(-x)#define zero(x) (((x)>0?(x):-(x))<eps)LL gcd(LL a,LL b) {return a?gcd(b%a,a):b;}typedef struct point {    LL x,y;}point;LL xmult(point p1,point p2,point p0){    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}int main(){    point A,B,C;    scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);    if(xmult(A,B,C)==0) printf("TOWARDS\n");    else if(xmult(A,B,C)>0){                printf("LEFT\n");        }    else {            printf("RIGHT\n");    }return 0;}

B 題 :加個數組記錄下就ok了,水。


int hash[maxn];int main(){    int n;    int A[maxn],C[maxn],B[maxn];    scanf("%d",&n);    clr(hash,0);    for(int i=1;i<=n;i++){        scanf("%d",&A[i]);        if(hash[A[i]]==0)            hash[A[i]]=i;    }    int m;    LL sum=0;    //BUG;    scanf("%d",&m);    for(int i=0;i<m;i++){        scanf("%d",&B[i]);        sum+=hash[B[i]];      //  BUG;    }    //BUG;    printf("%I64d",sum);    sum=0;    clr(hash,0);    for(int i=n,j=1;i>0;i--,j++){        if(hash[A[i]]==0){            hash[A[i]]=j;        }    }    for(int i=0;i<m;i++){        sum+=hash[B[i]];    }    printf(" %I64d\n",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.