Comet OJ - Contest # 13 Replenishment solution to a problem

A. sinister maze

The meaning of problems : In the two-dimensional plane coordinates, given a center coordinates (a, b), and the radius of the circle r, then given the coordinates of n points (x_i, y_i), find the number of points within the circle.

Data range : 0 <n <= 1e5, 0 <r, x, y <= 1e9

Ideas: for determining distance based on the Pythagorean theorem: sqrt ((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2)) <= r, i.e., in the range of the circle. Due to the larger problem of this data, sqrt may cause loss of precision, so a direct comparison open long long squared: (x1-x2) * ( x1-x2) + (y1-y2) * (y1-y2) <= r * r ;

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e5+7;

int main(){
    int n;
    ll a,b,r;
    cin>>n>>a>>b>>r;
    int ans = 0;
    for(int i=1;i<=n;i++){
        ll x,y;
        cin>>x>>y;
        if((x-a)*(x-a)+(y-b)*(y-b)<=r*r) ans++;
    }
    cout<<ans<<endl;
}

B. Yuhi glory

The meaning of problems : given length of string str n substring sequences found pink pink meet the conditions required of the composition from the sequence, two adjacent (adjacent to each other, such as p and i, n and k adjacent to each other) maximum. -1 coordinate difference
ideas : greedy: pi seeking the maximum interval, in a maximum time interval, nk coordinate maximum interval such as to make the maximum difference in coordinates pi, i.e., the leftmost p via whichever energy, i of whichever qualified thereof. Rightmost.

code:

#include <bits / STDC ++ H.> 
typedef Long  Long LL;
 the using  namespace STD;
 const  int MAXN = 1e6 + . 7 ;
 const  int INF = 0x3f3f3f3f ;
 int P0 [MAXN];
 int P1 [MAXN];
 int P2 [MAXN];
 int P3 [MAXN]; 

int fismin ( int COM, int P [], int len) {
 // find the first position is greater than the number 
    for ( int I = . 1 ; I <= len; I ++ ) {
         IF (P [ i]> com)return I; 
    } 
// not found return 0 
    return  0 ; 
} 
int fismax ( int COM, int P [], int len) {
 // find the last position of a number smaller than the 
    IF (P [len] <COM) return len ;
     the else {
         for ( int I = . 1 ; I <= len; I ++ ) {
             IF (P [I]> COM) return I- . 1 ; 
        } 
        return len; 
    } 
} 
int main () {
     int T;
    cin>>T;
    string s;
    while(T--){
        int len;
        cin>>len;
        cin>>s;
        int f0,f1,f2,f3;
        f0 = f1 = f2 = f3 = 0;
        //p-i间隔最大
        for(int i=0;i<len;i++){
            if(s[i]=='p') p0[++f0] = i;
            if(s[i]=='i') p1[++f1] =I;
             IF (S [I] == ' n- ' ) P2 [F2 ++] = I;
             IF (S [I] == ' K ' ) P3 [F3 ++] = I;        
        } 
        int ANS = - . 1 ;
         IF (F0 && F1 && F2 && F3) {
             int FF1, FF2;
             // 1.p0 leftmost, p3 rightmost, p2 only this p3 Right, p1 only this p2 Right P0-P1 
            FF2 = fismax (p3 [F3], p2, F2 );
             IF (FF2) { 
                FF1 = fismax (P2 [FF2], P1, F1);
                 IF (FF1) ANS = max (ANS, P1 [FF1] -p0 [ . 1]); 
            } 
            // 2.po leftmost, p1 p0 second only to the left, p3 most, p2 p3 remaining right-P2-P1 
            FF1 fismin = (p0 [ . 1 ], p1, F1); 
            FF2 = fismax (p3 [ F3], p2, F2);
             IF (&& FF1 FF2) { 
                ANS = max (ANS, p2 [FF2] - P1 [FF1]); 
            } 
            // 3.p0 left, p1 only this left, p2 only this left, p3 rightmost 
            FF1 = fismin (P0 [ . 1 ], P1, F1);
             IF (FF1) { 
                FF2 = fismin (P1 [FF1], P2, F2);
                 IF (FF2) ANS = max (ANS, P3 [F3] - P2 [FF2]); 
            } 

            IF (ANS <0) cout<<-1<<endl;
            else cout<<ans-1<<endl;
        }else{
            cout<<-1<<endl;
        }
    }
}
View Code

C. Sequence

The meaning of problems: The initial sequences of length n is 0, m times operation. Each operation is given range (l, r), the interval number within the sequence of all odd-numbered i th i into operation while before each operation, all the copy sequence. (If you have not understanding the problem, you can look original title analytical sample)

The sum of the maximum number of consecutive segments required after each operation.

Ideas: Counting Problems: Because it is a great statistical successive segments (consecutive sub-section) number, so we can count as dp, as recorded in the x position end (right end) of the number of consecutive subintervals f [x]. 0 is the initial length of such a sequence of 3, f [3] = 1;

For each interval change: we can know (l-1) and l, (r + 1) and the value of r is certainly not the same, so each modification operation after f [l-1] contribution and f [r] of increases, the number is increasing the number of multiplication, i.e., 2 ^ (i-1) when the i th operation.

No contribution to make the change, since each multiplier, which is multiplied by 2 so that it will count the number of.

Statistics last answer, put the contribution of all locations can be added.

#include <bits / STDC ++ H.>
 the using  namespace STD; 
typedef Long  Long LL;
 const  int MAXN = 2019 ;
 const LL MOD = 20,050,321 ;
 int n-, m; 
LL F [MAXN], P [MAXN]; 
// defined fx sequences represented, there is a great number of successive segments of the right end of the sequence x
 // x = n-, a_x! A_x. 1 + =,
 // every time that the contribution of different statistics from all the values in this case 1-n
 // because each of L, r value after different operations, and each update 2 ^ (i-1) sequences contribution, so ^ 2 + fr = fr (. 1-I);
 // Since 1 ~ i-1 and r + 1 ~ n part of the element is not changed, so the contribution of double 
int main () 
{ 
    CIN >> n >> m;
     // pretreatment 2 ^ (i-1)
    p[0]=1;for(int i=1;i<=m;i++)p[i]=(p[i-1]*2)%mod;
    f[n]=1;
    for(int i=1;i<=m;i++)
    {
        int l,r;
        cin>>l>>r;
      
        for(int j=1;j<l-1;j++) f[j]=(f[j]*2)%mod;
        for(int j=r+1;j<=n;j++) f[j]=(f[j]*2)%mod;

        f[l-1]=(f[l-1]+p[i-1])%mod;
        f[r]=(f[r]+p[i-1])%mod;
        
        ll ans=0;
        for(int j=1;j<=n;j++) ans=(ans+f[j])%mod;
        cout<<ans<<endl;
    }
    return 0;
}
View Code

 

 

Guess you like

Origin www.cnblogs.com/Tianwell/p/11827843.html