Testing Round #11
来源:互联网 发布:读研不要选女导师知乎 编辑:程序博客网 时间:2024/06/03 17:48
A. Up the hill
构造
#include <iostream>using namespace std;int a,b;int main() { cin >> a >> b; for (int i = b+1; i > 0; i--) cout << i << ' '; for (int i = 1; i <= a; i++) cout << i+b+1 << ' '; return 0;}
B. New York Hotel
模拟或者数学题
计算出离四个角最近的四个点,然后暴力枚举
// whn6325689#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>using namespace std;typedef long long ll;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define eps 1e-9#define INF 0x3f3f3f3f#define LLINF 1LL<<62template<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n){ if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}//-----------------------------------const int MAXN=1e5+9;ll dis(ll x1,ll y1,ll x2,ll y2){ return abs(x1-x2)+abs(y1-y2);}int n,m,cc,hh;ll a,b;ll ans=LLINF,id=-1;ll x[4],y[4];ll milu=LLINF,mild=LLINF,miru=LLINF,mird=LLINF,maxx;int main(){read(n),read(m);read(cc);for(int i=0;i<cc;i++){read(a),read(b);if(dis(0,0,a,b) <= milu){ milu=dis(0,0,a,b); x[0]=a,y[0]=b; } if(dis(n,0,a,b) <= mild){ mild=dis(n,0,a,b); x[1]=a,y[1]=b; } if(dis(0,m,a,b) <= miru){ miru=dis(0,m,a,b); x[2]=a,y[2]=b; } if(dis(n,m,a,b) <= mird){ mird=dis(n,m,a,b); x[3]=a,y[3]=b; }}read(hh);for(int i=1;i<=hh;i++){read(a),read(b);maxx=0;for(int j=0;j<4;j++)maxx=max(maxx,dis(a,b,x[j],y[j]));if(maxx<ans){ans=maxx;id=i;}}write(ans),putchar('\n'),write(id),putchar('\n');return 0;}
C. Deciphering
二分图的最优匹配,直接上KM模板
// whn6325689#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <complex>#include <fstream>#include <cassert>#include <cstdio>#include <bitset>#include <vector>#include <deque>#include <queue>#include <stack>#include <ctime>#include <set>#include <map>#include <cmath>using namespace std;typedef long long ll;typedef long double ld;typedef pair<ll, ll> pll;typedef complex<ld> point;typedef pair<int, int> pii;typedef pair<pii, int> piii;typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))#define mp(x,y) make_pair(x,y)#define pb(x) push_back(x)#define lowbit(x) (x&(-x))#define MID(x,y) (x+((y-x)>>1))#define eps 1e-9#define INF 0x3f3f3f3f#define LLINF 1LL<<62template<class T>inline bool read(T &n){ T x = 0, tmp = 1; char c = getchar(); while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar(); if(c == EOF) return false; if(c == '-') c = getchar(), tmp = -1; while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar(); n = x*tmp; return true;}template <class T>inline void write(T n){ if(n < 0) { putchar('-'); n = -n; } int len = 0,data[20]; while(n) { data[len++] = n%10; n /= 10; } if(!len) data[len++] = 0; while(len--) putchar(data[len]+48);}//-----------------------------------const int MAXN=66;int n, m;int adj[MAXN][MAXN];int labelx[MAXN], usedx[MAXN], lnk[MAXN];int labely[MAXN], usedy[MAXN];int mat;char s1[2000005];char s2[2000005];bool path(int i){ usedx[i]=1; for(int j=0; j<m; j++) { if(!usedy[j] && adj[i][j]!=-INF && !abs(adj[i][j]-labelx[i]-labely[j])) { usedy[j]=1; if(lnk[j]==-1 || path(lnk[j])) { lnk[j]=i; return true; } } } return false;}int match(){ mat=0; CLR(lnk,-1); CLR(labely,0); for(int i=0; i<n; i++) { labelx[i]=0; for(int j=0; j<m; j++) if(adj[i][j] > labelx[i]) labelx[i] = adj[i][j]; } for(int k=0; k<n; k++) { while(1) { CLR(usedx,0); CLR(usedy,0); if(path(k)) { mat++; break; } int del=INF; for(int i=0; i<n; i++) if(usedx[i]) for(int j=0; j<m; j++) if(!usedy[j] && adj[i][j]!=-INF) del=min(del,labelx[i]+labely[j]-adj[i][j]); if(del==0 || del==INF) break; for(int i=0; i<n; i++) if(usedx[i]) labelx[i] -= del; for(int j=0; j<m; j++) if(usedy[j]) labely[j] += del; } } int sum=0; for(int i=0; i<n; i++) sum+=labelx[i]; for(int j=0; j<m; j++) sum+=labely[j]; return sum;}int main(void){ int len, k; int a,b; read(len),read(k); gets(s1),gets(s2); n=m=k; for(int i=0; i<len; i++) { if(islower(s1[i])) a=s1[i]-'a'; else a=s1[i]-'A'+26; if(islower(s2[i])) b=s2[i]-'a'; else b=s2[i]-'A'+26; adj[a][b]++; } int r=match(); write(r),putchar('\n'); for(int i=0; i<k; i++) for(int j=0; j<k; j++) if(lnk[j]==i) if(j>=26) printf("%c", j+'A'-26); else printf("%c", j+'a'); puts(""); return 0;}
0 0
- Testing Round #11
- Codeforces Testing Round #3
- Codeforces Testing Round #3
- Codeforces Testing Round #9
- 【Codeforces】Testing Round #12
- Testing Round #12
- Testing Round #12
- Codeforces Testing Round #10 C
- Testing Round #12 C Subsequences
- Restaurant Testing Round #12 B
- Codeforces Testing Round #14 (Unrated)
- Testing Round #14 (Unrated) A
- Testing Round #14 (Unrated) B
- Testing Round #14 (Unrated) B
- Testing Round #14 (Unrated) C
- Codeforces Testing Round #14 (Unrated)
- Codeforces Testing Round #14 (Unrated)
- Codeforces Testing Round #5 B DFS
- iOS开发UI篇—xib的简单使用
- 器件封装
- 【扩展知识2】函数strlen()和非函数sizeof的使用
- 在线会计页面
- C++/C笔试面试题目大大的集合
- Testing Round #11
- mysql show processlist命令 详解
- ORACLE如何使用DBLINK连接另一个数据库
- android工具类中自定义监听处理异步方法问题
- PHP SPL 标准库
- 重拾算法之路——线性时间选择
- 在CView中如何得到CMainFrame的变量
- TestFlight——完美的iOS app测试方案
- Mac升级到OS X10.10系统以后cocoapods无法正常使用