2018CCPC網路賽部分題題解

2021-08-25 23:00:49 字數 2807 閱讀 1579

通過這場比賽再次認識到自己的菜,被大佬們吊著錘。。。開場的乙個小時節奏還算不錯,先過了1004,1009也有思路。接著,伺服器就炸了。。。交上去的一發也wa了,比賽中途居然在一直刷網頁。。。還好1009把bug找出來a掉了。。。可是1003還是找不出規律啊,1010的dp還是不會優化啊,1001貪心也貪錯了啊。。。

不說了,總結起來還是自己太弱了。。。(只能靠賽後補題來防止自己更菜了。。。)

1004 -  find integer(hdu6441)

題意:找到一組b和c,使得a^n+b^n=c^n。沒有輸出-1,-1。

這題看一眼應該都想到費馬大定理了。n>=3時是無解的。那麼只看n=1和n=2即可,n=1是取b=1,c=a+1即可。關鍵在於n=2時,要想到勾股數的公式(1)當a為大於1的奇數2n+1時,b=2n^2+2n, c=2n^2 +2n+1(2)當a為大於4的偶數2n時,b=n^2-1, c=n^2+1

**:

#include#include#include#include#include#include#include#include#include#include#includeusing namespace std; 

typedef long long ll;

int main()

else if(n==2)

else

printf("%lld %lld\n",b,c); }}

}return 0;

}

1009  tree and permutation(hdu6446)

題意:從給出的序列的乙個端點到另乙個端點的費用即為s(i),求所有序列的全排列s(i)的和

這題是隊友想出來的,orz果爺。。。

通過觀察可以發現只要計算這個序列中任意兩點距離的總和 乘上  2(n-1)f(n-2), 其中f(i)代表i的階乘。

後面是怎麼得到的呢?如(1 3)和(3 1)算了兩次,所以乘2。後面的可以將此時選出來的兩個數看成乙個整體,乙個組合數就搞定了(很像高中的排列組合題)。。。

那麼任意兩點間距離怎麼算呢?其實對邊統計就行了,對每條邊而言,經過這條邊的總次數就是這條邊兩邊點數的乘積。所以這道題其實1遍dfs即可。。。

**:

#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;

#define ll long long

const ll mod = 1e9+7;

const int maxn = 1e5+9;

int n;

ll ans, f[maxn], cnt_son[maxn];

struct node;

vectore[maxn];

void dfs(int fa, int cur) node;

node node[maxn];

ll nx[maxn];

ll ny[maxn];

ll max[maxn<<2];

ll max;

int tx,ty;

int t,n;

bool cmp(node a,node b)

ll query(int l,int r,int l,int r,int rt)

int m = (l + r) >> 1;

ll ret = 0;

if (l <= m) ret = max(ret , query(l , r , lson));

if (r > m) ret = max(ret , query(l , r , rson));

return ret;

}int main()

sort(nx+1,nx+1+cntx);

sort(ny+1,ny+1+cnty);

tx=unique(nx+1,nx+cntx+1)-(nx+1);

ty=unique(ny+1,ny+cnty+1)-(ny+1);

for(int i=1;i<=n;i++)

sort(node+1,node+1+n,cmp);

printf("%d %d\n",tx,ty);

int y;

ans=0;

for(int i=1;i<=n;i++)

else

}printf("%lld\n",ans);

} return 0;

}

1001  buy and resell  (hdu6438)

思路:每個地方有乙個**,可以在每個地方選擇買,賣,或不買不賣。同時可攜帶多個商品,初始錢無限,問最多賺多少錢。

和   差不多,

可以看看這篇題解

唯一不同的是這題要求交換次數最小。其實也好像,比如1 -> 2 ->5 -> 10,中間多算了2和5,那麼把他們減掉就可以了。也就是對於既賣又買的點減掉即可。。。

**:

#include#include#include#include#includeusing namespace std;

typedef long long ll;

const int maxn=1e5+10;

priority_queue, greater> q;

mapmp;

int main()

else

else

mp[tem]++;}}

}printf("%lld %d\n",ans,cnt);

}return 0;

}

其實還想補個1007,但由於我太弱了,等過兩天再補,待更。。。 

2018CCPC吉林賽區 重現賽 部分

題意 判斷所給表示式的奇偶性 思路 打表發現1 3為奇數,4 8為偶數,9 15為奇數,16 24為偶數,25 35為奇數 include using namespace std typedef long long ll const int inf 0x3f3f3f3f const int max ...

2018CCPC網路賽A(優先佇列,思維)

include using namespace std priority queue q int main q.push 賣出 tmp x q.top first 如果前面沒有比它更小的,相當於放進去乙個標記為1的 如果有比它更小的,相當於執行買賣 if q.top second 1 除了第一次進佇...

秦皇島2018CCPC現場賽

所有的磨難挫折,都該慶幸,它來的還不算晚.大海我來了 來之前,就聽說這裡有海,很欣喜.畢竟乙個土生土長的山西人,還沒 看過大海.坐了一夜的火車,下車直奔博維酒店,距離比賽地點特別近,步行10分鐘,搞定了報道,然後就回酒店補覺了.下午ge掉了開幕式,在熱身賽開始前,堪堪來到賽場.熱身賽 cqw和xzw...