7.2

//单调队列

#include
using namespace std;
deque<int> 
int main( ){
    int a[1000];
    for( itn i=0 ;i<1000 ;i++){
    if(q.empty()){
        q.push_back( a[i] );
    }
    else if( q.back()>a[i]){
        while( !q.empty() && q.back()>a[i]){
            q.pop_back();
        }
        q.push_back( a[i] );
    }
    else q.push_back( a[i] );
    }
    return 0;
}

#include using namespace std; deque<int> dq; const int inf =0x3f3f3f3f; int pic[550][550] ,m ,n ,k ,q; int mx[550][550] , r, c; vector <int> mn; void init(){ for(int j=1 ;j<=m; j++){ dq.clear(); for( int i=1 ;i<=k ;i++){ //cout<<"now "< if( dq.empty() )dq.push_back( pic[i][j] ); else{ while( !dq.empty() && dq.back()<pic[i][j] ){ //cout<<"pop "< dq.pop_back(); } dq.push_back( pic[i][j] ); } } for( int i=1+k ;i<=n ;i++){ mx[i-k][j] = dq.front(); //cout< if( pic[i-k][j] == dq.front() )dq.pop_front(); if( dq.empty() )dq.push_back( pic[i][j] ); else{ while( !dq.empty() && dq.back()<pic[i][j] ){ //cout<<"pop "< dq.pop_back(); } dq.push_back( pic[i][j] ); } } mx[n+1-k][j] = dq.front(); //cout<//cout<<"here\n"; } return; } int main( ){ ios::sync_with_stdio( false ); memset( pic ,inf ,sizeof( pic )); cin>>n>>m>>k>>q; while( q--){ cin>>r>>c; cin>>pic[r][c]; } init(); //cout<<"here"< for( int i=1 ;i<=n-k+1 ;i++){ dq.clear(); for( int j=1 ;j<=k ;j++ ){ //cout<<"now "< if( dq.empty() )dq.push_back( mx[i][j] ); else{ while( !dq.empty() && dq.back()<mx[i][j] ){ dq.pop_back(); //cout<<"pop "< } dq.push_back( mx[i][j] ); } } for( int j=1+k ;j<=m ;j++ ){ mn.push_back( dq.front() ); //cout< if( mx[i][j-k]==dq.front() )dq.pop_front(); if( dq.empty() )dq.push_back( mx[i][j] ); else{ while( !dq.empty() && dq.back()<mx[i][j] ){ dq.pop_back(); } dq.push_back( mx[i][j] ); } } mn.push_back( dq.front() ); //cout< } sort(mn.begin() ,mn.end()); if(mn[0]==inf)cout<<"-1\n"; else cout<0]; return 0; }

//
技巧暴力 #include #define N 100005 using namespace std; typedef long long ll; ll n ,k ,ans=0; ll a[N] ,sum[N]={0}; vector pk; mapint> mp; int main(){ ios :: sync_with_stdio( false ); cin >>n>>k; for( int i=1 ;i<=n ;i++){ cin>>a[i]; sum[i] = sum[i-1]+a[i]; } pk.push_back(1); ll t = k; while( abs(k) < 1e14+5 && k!=1 ){ pk.push_back(k); k *= t; //cout< } sort( pk.begin(), pk.end()); int sz = pk.size(); mp[0] = 1; for( int i=1 ;i<=n ;i++){ ll tmp; for( int j=0; j){ tmp = sum[j] - sum[i]; //cout<< tmp%t< ans +=mp[sum[i] - pk[j]]; } mp[sum[i]]++; } cout<<ans; return 0; }

//
思维 快速幂 #include #define MOD 1000000000+7 using namespace std; typedef long long ll; ll pow(ll n ,ll p){ ll ans = 1; while( p ){ if( p&1 )ans*=n; ans %= MOD; n *= n; n %= MOD; p >>= 1; } return ans; } int main( ){ ios :: sync_with_stdio( false ); ll n; ll a=0 ,g=0 ,c=0 ,t=0 ,mx ,k; string s; cin >>n >>s; for( int i=0 ;i){ if( s[i]=='A' )a++; else if( s[i]=='G' )g++; else if( s[i]=='C' )c++; else t++; } mx = max(a ,max( g ,max( c ,t ) ) ); k = (a==mx)+(g==mx)+(c==mx)+(t==mx); cout<<pow(k ,n); }
//

C - Elections


//三分
//意想不到的错误!a!wsl!
#include

using namespace std;
typedef long long ll;
int n ,m;
struct Voter{
    int a,b; 
    bool operator < (const Voter & s)const{
         return b < s.b;
    }
} voter[100050];
int can_vote[100050]={0};
int tem_vote[100050];
int vis[100050];

// 检查对象:最优票数,使得花费最少
// 1,其他候选人不得高于此票数
// 2,自身不得低于此票数
// 3,满足规则1,2的基础上,
// 不难发现,最终结果最优时自身票数一定恰达到此标准 
int check( int level){
    //cout<<"level "<
    int sum = 0;
    
    memset( vis ,0 ,sizeof(vis));
    
tem_vote[0] = 0;
for( int i=0 ;i) tem_vote[ voter[i].a ]
= can_vote[ voter[i].a ]; //难以debug的错误语句,原:tem_vote[i] = can_vote[i]; for( int i=0 ;i){ int can = voter[i].a, mny = voter[i].b; if( can == 0)vis[i] = 1; else{ // cout< if( tem_vote[can] >= level){ sum += mny; tem_vote[ can ]--; tem_vote[ 0 ]++; vis[i] = 1; //cout<<"a i "<//cout< } } } // cout< if( tem_vote[0] < level) for( int i=0 ;i){ if( vis[i] )continue; int can = voter[i].a, mny = voter[i].b; tem_vote[0]++; sum += mny; //cout<<"i "< if( tem_vote[0] >= level) break; } //cout<<"sum "< return sum; } int main(void){ ios::sync_with_stdio( false ); memset( can_vote ,0 ,sizeof(can_vote)); cin >> n; for( int i=0 ;i){ cin >>voter[i].a >>voter[i].b; //cout<< voter[i].a<<' '< can_vote[ voter[i].a ]++; } sort( voter ,voter+n ); int l = 1 ,r = n ,ans; while( l<=r ){ int l_mid = l+(r-l)/3; int r_mid = r-(r-l)/3; if( check(l_mid)<=check(r_mid) ){ ans = check(l_mid); r= r_mid-1; } else{ ans = check(r_mid); l = l_mid+1; } } cout << ans << endl; return 0; }
//cf - edu40 -D 
//图论 bfs球最短路的应用 

#include 
using namespace std;

const int inf = 0x3f3f3f3f;
int sp[1500][1500] ,edge[1500][1500] ,vis[1500];
int n ,m ,s ,t;

void bfs( int x ){
    memset( vis ,0 ,sizeof(vis) );
    queue<int> q;
    q.push( x );
    vis[x] = 1;
    while( !q.empty() ){
        int t = q.front(); q.pop();
        for( int i=1 ;i<=n ;i++){
            if( edge[t][i] && !vis[i] ){
                vis[i] = 1;
                sp[i][x] = sp[x][i] = sp[t][x]+1;
                q.push(i);
            }
        }
    }
    return ;
}

int main( ){
    memset( sp ,inf ,sizeof(sp) );
    memset( edge ,0 ,sizeof(edge) );
    ios::sync_with_stdio( false );
    cin >>n >>m >>s >>t;
    while( m-- ){
        int a, b;
        cin>>a >>b;
        sp[a][b]=edge[a][b]=1;
        sp[b][a]=edge[b][a]=1;
    }
    //init
    for( int i=1 ;i<=n ;i++){
        sp[i][i] = 0;
    }
    bfs( s ); bfs( t );
    
    int ans = 0;
    for( int i=1 ;i<=n ;i++){
        for( int j=i+1 ;j<=n ;j++){
            if( !edge[i][j] )
                //增边后对新增s->t路径的长度判断 
                if( sp[s][i]+sp[t][j]+1>=sp[s][t] && sp[s][j]+sp[t][i]+1>=sp[s][t])
                ans++;
        }
    }    
    cout<<ans;
    return 0;
}
 
  

 

/*
16 
0 12
0 12
0 12
0 12
2 1
2 1
3 500
3 500
3 500
3 500
3 500
4 500
4 500
4 500
4 500
4 500
*/

 

//巧用与标准相对+-的贪心 
// E-tap 
#include
#define rep(i ,x ,y) for(int i=x ;i<=y ;++i)
#define repd(i ,x ,y) for(int i=y ;i>=x ;--i)
#define N 200050
using namespace std;

typedef long long ll;
typedef long double ld;
int n ,T ,a[N] ,t[N];

struct Tap{
    int a ,t;
    Tap( int a ,int t):a(a) ,t(t){}
    bool operator < (const Tap & s)const{
         return t < s.t;
    }
};
vector x[2];

int main( ){
    ld ans = 0;
    ll sum[2] = {0 ,0};
    scanf( "%d%d" ,&n ,&T);
    rep(i ,1 ,n)scanf( "%d" ,&a[i]);
    rep(i ,1 ,n){
        scanf( "%d" ,&t[i] );
        t[i] -= T;
        if( t[i]==0 )ans += a[i];
        else x[t[i]<0].push_back( Tap( a[i] ,abs( t[i] )) );
    }
    //cout<<"1 "<
    
    rep( i, 0 ,1){
        for( vector::iterator it= x[i].begin() ;it!=x[i].end() ;it++ )
           sum[i] += 1ll * (* it).a * (*it).t;
    }
    
    if( sum[0] >sum[1] ){
        swap(x[0] ,x[1]);
        swap(sum[0] ,sum[1]);
    }
    
    sort( x[1].begin() ,x[1].end() );
    
    for( vector::iterator it= x[0].begin() ;it!=x[0].end() ;it++ )
       ans += (* it).a;
    
    //cout<<"2 "<
    for( vector::iterator it= x[1].begin() ;it!=x[1].end() ;it++ ){
        if( 1ll * (* it).t *(* it).a >= sum[0] ){
            //cout << ans<<" "<
            ans += 1.0* sum[0]/(* it).t; 
            //cout<
            break;
        }
        //cout << ans<<" "<
        ans += (* it).a ,sum[0] -= 1ll*(* it).t *(* it).a;
    }
    printf("%Lf\n" ,ans);
    return 0;
}

你可能感兴趣的:(7.2)