2017 Multi-University Training Contest - Team 5
2017 Multi-University Training Contest - Team 5
06 / hdu6090 思维
tags: 主要是要想到,一个连通块中,最小化内部距离和,一定是一个点连剩下所有点。
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define MP make_pair #define PB push_back #define fi first #define se second typedef long long ll; const int N = 200005; int main() { ll n, m; int T; scanf("%d", &T); while(T--) { scanf("%lld%lld", &n, &m); ll ans=0; if(m<=n-1) { ans = m*m*2 + (n-(m+1))*(m+1)*n*2 + (n-(m+1))*(n-(m+2))*n; } else { ans = (n-1)*(n-1)*2 - (m-(n-1))*2; ans = max(ans, n*(n-1)); } printf("%lld\n", ans); } return 0; }
08 / hdu6092 dp,类似反过来的背包
tags: dp[now] 表示当前子集和为 now 的方案数,从1~m遍历过去,如果 dp[now] != b[now] 则需要更新,更新操作是:从 m~now ,dp[j] += dp[i-now] ,即类似背包反过来更新。
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define MP make_pair #define PB push_back #define fi first #define se second typedef long long ll; const int N = 200005; int n, m, a[60], cnt; ll b[N], dp[N]; int main() { int T; scanf("%d", &T); while(T--) { mes(dp, 0); dp[0] = 1; cnt = 0; scanf("%d%d", &n, &m); rep(now,0,m) { scanf("%lld", &b[now]); while(dp[now]!=b[now]) { per(i,m,now) dp[i] += dp[i-now]; a[++cnt] = now; } } rep(i,1,n) if(i!=n) printf("%d ", a[i]); else printf("%d\n", a[i]); } return 0; }
11 / hdu6095 水
#include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i) #define mes(a,b) memset(a,b,sizeof(a)) #define INF 0x3f3f3f3f #define MP make_pair #define PB push_back #define fi first #define se second typedef long long ll; const int N = 200005; int n, k, a[N]; int main() { int T; scanf("%d", &T); while(T--) { scanf("%d%d", &n, &k); rep(i,1,n) scanf("%d", &a[i]); sort(a+1, a+1+n); int cnt = 1; per(i,n-1,1) { if(a[i+1]-a[i]>k) break; else ++cnt; } printf("%d\n", cnt); } return 0; }