Codeforces Round 313 (DIV1)

Source: Internet
Author: User


Question A:

Main topic:

The length of the six sides of a hexagon with a total of 120 degrees in the inner angle is given, and the equilateral triangle consisting of how many sides are 1.


Problem Solving Ideas:

The hexagonal complement is a large equilateral triangle, then the side length of the large equilateral triangle is the sum of the adjacent three sides of the hexagon, then minus the part of the complement,

The part of the complement is a equilateral triangle of three sides for the length of the known 3 nonadjacent hexagonal side length, a equilateral triangle with a side length of a, by a*a sides

A small triangle with a length of 1.


Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int Main () {    int a[10];    for (int i=0;i<6;i++)    {        scanf ("%d", &a[i]);    }    Long long cur=a[0]+a[1]+a[2];    Long long ans=cur*cur-a[0]*a[0]-a[2]*a[2]-a[4]*a[4];    cout<<ans<<endl;    return 0;}

B. Equivalent Strings


Main topic:

determines the string equality based on the given rule.


Problem Solving Ideas:

Follow the test instructions to write it recursively.


Code:

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring>using namespace    std;const int Maxn=200000+1000;char S1[maxn];char s2[maxn];int judge (int st1,int en1,int st2,int en2) {int sign=0;            for (int i=st1,j=st2;i<=en1;i++,j++) {if (S1[i]!=s2[j]) {sign=1;        Break    }} if (sign==0) return 1;            else {if ((en1-st1+1)%2==0) {int mid1=st1+ (en1-st1+1)/2-1;            int mid2=st2+ (en2-st2+1)/2-1;            if (judge (St1,mid1,st2,mid2) &&judge (MID1+1,EN1,MID2+1,EN2)) return 1;        if (judge (St1,mid1,mid2+1,en2) &&judge (MID1+1,EN1,ST2,MID2)) return 1; }} return 0;}    int main () {int len1,len2;    scanf ("%s%s", S1,S2);    Len1=strlen (S1);    Len2=strlen (S2);    if (len1!=len2) cout<< "no\n" <<endl;       else {int sign;       Sign=judge (0,len1-1,0,len1-1); if (sign) printf ("yes\n");      else printf ("no\n"); } return 0;}


C. Gerald and Giant Chess


Main topic:

Given h*w lattice, n non-walking points, from (to () to (H,W) points, each time only down or to the right, how many ways to go?


Problem Solving Ideas:

First of all, do not consider the point of not to go, there are C (h+w-2,h-1) kind of way, a total of walking h+w-2 step, down the h-1 step. Then consider the non-walking

Point, for a non-walking point (x, y), it goes to this point of the walk is dp[i], it is less to go is dp[i]*c (h-x,w-y,h-x), so that each cannot walk

The point is the end, you can find out all the number of walk.


Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int h,w,n;const int Maxn=200000+100;const int Mod=1000000000+7;long long C[maxn];long long Inv[maxn];long long dp[500    0];struct node{int x; int y;}    A[10000];long long Pow_mod (Long long a,int b)//matrix fast Power {long long ans=1;        while (b) {if (b&1) ans= (ans*a)%mod;        A= (a*a)%mod;    B=B/2; } return ans; Long long com (int x,int y)//Combine number C (x, y) {return ((C[x]*inv[y])%mod*inv[x-y])%mod;}    BOOL CMP (node U,node v) {if (u.x==v.x) return u.y<v.y; return u.x<v.x;}    int main () {scanf ("%d%d%d", &h,&w,&n);    for (int i=0;i<n;i++) scanf ("%d%d", &a[i].x,&a[i].y);    Sort (a,a+n,cmp);    Long Long ans=0;    C[0]=1;    for (int i=1;i<maxn;i++) C[i]=c[i-1]*i%mod;    Inv[0]=1;    for (int i=1;i<maxn;i++) inv[i]=pow_mod (c[i],mod-2);//Fermat theorem inversion, a^ (p-2) =a^ ( -1) ans=com (h+w-2,h-1); for (int i=0;i<n;i++)    {dp[i]=com (a[i].x+a[i].y-2,a[i].x-1);            for (int j=0;j<i;j++)//The number of methods of the first point of the method {if (A[J].X&LT;=A[I].X&AMP;&AMP;A[J].Y&LT;=A[I].Y)//Determine whether I point can be reached                {dp[i]-= (dp[j]*com (a[i].x-a[j].x+a[i].y-a[j].y,a[i].x-a[j].x))%mod;            dp[i]= (dp[i]+mod)%mod;    }} ans= (ans-(dp[i]*com (h+w-a[i].x-a[i].y,h-a[i].x))%mod+mod)%mod;    } cout<<ans<<endl; return 0;}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces Round 313 (DIV1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.