2019icpc銀川網絡賽


 外面吵得風生水起,我校平靜地在打比賽,絲毫不知道這次比賽的題目就是把2018銀川邀請賽的題照搬過來了QAQ,主辦方真牛逼。。

 

A Maximum(思維)

題意:維護一個棧,支持入棧和出棧操作,並計算每次操作后的棧中最大值,得到最終結果。

思路:

  這題真的是,我和hxc輪流做這道題,被坑慘了,一直以為使用數據結構來做,沒想到點上去。思維題,每次保證棧頂為棧中最大元素。如果當前入棧的元素為x,當前棧頂元素為y,如果x>=y,這個沒問題,直接入棧就行了; 如果x<y,我們相當於直接用y替換x,再入棧即可。

  吸取教訓,這種過的人很多的,不要想復雜,怎么簡單怎么來。

AC代碼:

#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
using namespace std;

const int maxn=5e6+5;
typedef unsigned int UI;
int T,cas,top;
UI stk[maxn];
long long ans;

int n,p,q,m;    
unsigned int SA,SB,SC;
unsigned int rng61(){
    SA^=SA<<16;
    SA^=SA>>5;
    SA^=SA<<1;
    unsigned int t=SA; SA=SB;
    SB=SC;
    SC^=t^SA;
    return SC;
}

void gen(){
    scanf("%d%d%d%d%u%u%u",&n,&p,&q,&m,&SA,&SB,&SC);
    for(int i=1;i<=n;++i){
        if(rng61()%(p+q)<p){
            stk[++top]=rng61()%m+1;
            stk[top]=max(stk[top-1],stk[top]);
        }
        else
            if(top>0) --top;
        ans^=1LL*i*stk[top];
    }
}

int main(){
    scanf("%d",&T);
    while(T--){
        ans=0;
        top=0;
        gen();
        printf("Case #%d: %lld\n",++cas,ans);
    }
    return 0;
}

 


 

 

B. Rolling The Polygon

hxc寫得。

AC代碼:

#pragma GCC optimize(2)
#include <cstdio>
#include <queue>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <fstream>
#include <cassert>
#define ll long long
#define R register int
#define I inline void
#define lc c[x][0]
#define rc c[x][1]

using namespace std;
const int INF = 0x3f3f3f3f;

const int maxn = 100;
struct node
{
    double x,y;
}pp[maxn],qq;

double rad(node a,node b,node c)
{
    return acos(((a.x - b.x) * (c.x - b.x) + (a.y - b.y) * (c.y - b.y)) / sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) / sqrt((c.x - b.x) * (c.x - b.x) + (c.y - b.y) * (c.y - b.y)));
}

int t,n;
int main()
{
    scanf("%d",&t);
    int o = t;
    while(t--)
    {
        double ans = 0;
        scanf("%d",&n);
        for(int i = 1; i <= n; i++)
            scanf("%lf%lf",&pp[i].x,&pp[i].y);
        scanf("%lf%lf",&qq.x,&qq.y);

        for(int i = 1; i <= n; i++)
        {
            //printf("%qwe%lf\n",rad(pp[(i - 2 + n * 2) % n + 1],pp[i],pp[i % n + 1]));
            double temp = sqrt((qq.x - pp[i].x) * (qq.x - pp[i].x) + (qq.y - pp[i].y) * (qq.y - pp[i].y));
            ans += temp * (M_PI - rad(pp[(i - 2 + n * 2) % n + 1],pp[i],pp[i % n + 1]));
        }
        printf("Case #%d: %.3lf\n",o - t,ans);
    }
}

 


 

 

C. Ceasar Cipher (水題,模擬就行了)

AC代碼:

#include<cstdio>
#include<algorithm>
using namespace std;

int T,n,m,cas,num;
char s1[55],s2[55],s3[55];

int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        scanf("%s%s%s",s1,s2,s3);
        num=(s1[0]-s2[0]+26)%26;
        printf("Case #%d: ",++cas);
        for(int i=0;i<m;++i)
            printf("%c",(s3[i]-'A'+num)%26+'A');
        printf("\n");
    }    
    return 0;
}

 


 

 

D. Moving On (概率)

題意:

  第一問:n個人對應n個座位,按1~n的順序選擇,1號任意選,i號選i(如果i未選)或任意選(如果i已選),i>=2,求最后一個選的人選對的概率。

  第二問:m個人對應m個座位,按任意次序選擇(m!種排列),1號任意選,i號選i(如果i未選)或任意選(如果i已選),i>=2,求最后一個選的人選對的概率。

思路:

  第一問dfs打表發現概率為0.5,第二種情況對於m!種排列:

    如果1在最后選,那么一定能選對,概率為1,有(m-1)!種。

    如果1不在最后,1前面的一定能選對,從1開始往后的就變成第1問,概率為0.5,有m!-(m-1)!種。

  故第二種概率為(m-1)!/m!*1+(m!-(m-1)!)/m!*0.5=(m+1)/(2*m)。

剛開始算錯了,卡了兩小時QAQ。。

AC代碼:

#include<cstdio>
#include<algorithm>
using namespace std;

int T,n,m,cas;

int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        printf("Case #%d: ",++cas);
        if(n==1) printf("1.000000 ");
        else printf("0.500000 ");
        printf("%.6f\n",1.0*(m+1)/(2.0*m));    
    }
    return 0;
}

 


 

 

F. Moving On(floyd變形)

題意:給定一個圖,每個點有個權值r[i],多次詢問,每次詢問u到v的最短路,且該最短路不經過權值大於w的點。

思路:按權值進行排序,然后floyd,dp[k][i][j]表示經過排序后的前k個點i到j的最短路。詢問的時候二分查找即可。但是這題似乎卡常,我定義數組dp[i][j][k]會T,而dp[k][i][j]就A了。絕望-_-。。

AC代碼:

#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn=205;
const int inf=0x3f3f3f3f;
int T,cas,n,m;
int u,v,w,dp[maxn][maxn][maxn];

struct node{
    int val,id;
}a[maxn];

bool operator < (const node& x,const node& y){
    return x.val<y.val;
}

int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);    
        for(int i=1;i<=n;++i){
            scanf("%d",&a[i].val);
            a[i].id=i;
        }
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)
                scanf("%d",&dp[0][i][j]);
        sort(a+1,a+n+1);
        for(int k=1;k<=n;++k)
            for(int i=1;i<=n;++i)
                for(int j=1;j<=n;++j)
                    dp[k][i][j]=min(dp[k-1][i][j],dp[k-1][i][a[k].id]+dp[k-1][a[k].id][j]);
        printf("Case #%d:\n",++cas);
        while(m--){
            scanf("%d%d%d",&u,&v,&w);
            int l=1,r=n,mid;
            while(l<=r){
                mid=(l+r)>>1;
                if(a[mid].val<=w) l=mid+1;
                else r=mid-1;
            }
            printf("%d\n",dp[r][u][v]);    
        }
    }
    return 0;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM