当前位置: 首页 > 编程日记 > 正文

2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

A Drawing Borders

很多构造方法,下图可能是最简单的了

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
struct Point{ int x,y; };
Point a[maxn];  int numa=0;
Point b[maxn];  int numb=0;
vector<pair<double,double> > va;
vector<pair<double,double> > vb;
void checka()
{va.push_back({3000,3000});va.push_back({3000,2999});for(int i=numa;i>=1;i--){va.push_back( { a[i].x*1.000-0.3,2999} );va.push_back( { a[i].x*1.000-0.3,a[i].y*1.000+0.1} );va.push_back( { a[i].x*1.000+0.1,a[i].y*1.000+0.1} );va.push_back( { a[i].x*1.000+0.1,a[i].y*1.000-0.1} );va.push_back( { a[i].x*1.000-0.3,a[i].y*1.000-0.1} );while(i-1>=1 && a[i-1].x==a[i].x){i--;va.push_back( { a[i].x*1.000-0.3,a[i].y*1.000+0.1} );va.push_back( { a[i].x*1.000+0.1,a[i].y*1.000+0.1} );va.push_back( { a[i].x*1.000+0.1,a[i].y*1.000-0.1} );va.push_back( { a[i].x*1.000-0.3,a[i].y*1.000-0.1} );}va.push_back( {a[i].x*1.0000-0.3,-1200} );va.push_back( {a[i].x*1.0000-0.39,-1200} );va.push_back( {a[i].x*1.0000-0.39,2999});}va.push_back({-3000,2999});va.push_back({-3000,3000});
}
void checkb()
{vb.push_back({-3000,-3000});vb.push_back({-3000,-2999});for(int i=1;i<=numb;i++){vb.push_back( { b[i].x*1.000+0.3,-2999} );vb.push_back( { b[i].x*1.000+0.3,b[i].y*1.000-0.1} );vb.push_back( { b[i].x*1.000-0.1,b[i].y*1.000-0.1} );vb.push_back( { b[i].x*1.000-0.1,b[i].y*1.000+0.1} );vb.push_back( { b[i].x*1.000+0.3,b[i].y*1.000+0.1} );while(i+1<=numb && b[i+1].x==b[i].x){i++;vb.push_back( { b[i].x*1.000+0.3,b[i].y*1.000-0.1} );vb.push_back( { b[i].x*1.000-0.1,b[i].y*1.000-0.1} );vb.push_back( { b[i].x*1.000-0.1,b[i].y*1.000+0.1} );vb.push_back( { b[i].x*1.000+0.3,b[i].y*1.000+0.1} );}vb.push_back( { b[i].x*1.000+0.3,1200} );vb.push_back( { b[i].x*1.000+0.39,1200} );vb.push_back( { b[i].x*1.000+0.39,-2999} );}vb.push_back({3000,-2999});vb.push_back({3000,-3000});
}
bool upa(Point a,Point b){if(a.x==b.x) return a.y<b.y;return   a.x<b.x;}
bool upb(Point a,Point b){if(a.x==b.x) return a.y<b.y;return   a.x<b.x;}
int main()
{int n ; scanf("%d",&n);for(int i=1;i<=n;i++){int x,y,z; scanf("%d %d %d",&x,&y,&z);if(z==1) a[++numa].x=x,a[numa].y=y;if(z==2) b[++numb].x=x,b[numb].y=y;}sort(a+1,a+1+numa,upa);   checka();sort(b+1,b+1+numb,upb);   checkb();printf("%d\n",va.size()); for(int i=0;i<va.size();i++) printf("%.4f %.4f\n",va[i].first,va[i].second);printf("%d\n",vb.size()); for(int i=0;i<vb.size();i++) printf("%.4f %.4f\n",vb[i].first,vb[i].second);
}
View Code

B Buildings

polya定理

代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int quick(int a,int n)
{int ans=1;while(n){if(n%2==0) {a=a%mod*a%mod;n=n/2; }else       {ans=ans%mod*a%mod;   n--;   }}return ans;
}
int p[500+10];
int32_t main()
{int n,m,c; cin>>n>>m>>c;//  m  temp;int temp=quick(c,n*n); //cout<<temp<<endl;p[0]=1;for(int i=1;i<= m;i++) p[i]=p[i-1]%mod*temp%mod;int a=0;for(int i=0;i<m;i++)  a+=p[__gcd(i,m)],a=a%mod;int ans=a*quick(m,mod-2)%mod;cout<<ans<<endl;
}
View Code

C Joyride

dp + 记忆化搜索

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//headconst int N = 1e3 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
LL dp[N][N];
vector<int> g[N];
int x, n, m, T, u, v;
int t[N], p[N];
LL dfs(int u, int m) {if(m > x) return INF;if(~dp[u][m]) return dp[u][m];if(u == 1 && m == x) return dp[u][m] = 0;dp[u][m] = INF;for (int v : g[u]) {dp[u][m] = min(dp[u][m], dfs(v, m+T+t[v]) + p[v]);}dp[u][m] = min(dp[u][m], dfs(u, m+t[u])+p[u]);return dp[u][m];
}
int main() {mem(dp, -1);scanf("%d", &x);scanf("%d %d %d", &n, &m, &T);for (int i = 1; i <= m; ++i) scanf("%d %d", &u, &v), g[u].pb(v), g[v].pb(u);for (int i = 1; i <= n; ++i) scanf("%d %d", &t[i], &p[i]);LL tmp = dfs(1, t[1]) + p[1];if(t[1]*2 > x || tmp >= INF) printf("It is a trap.\n");else printf("%lld\n", tmp);return 0;
}
View Code

D Pants On Fire

拓扑排序

代码:

#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>/*⊂_ヽ\\ Λ_Λ  来了老弟\('ㅅ')> ⌒ヽ/   へ\/  / \\レ ノ   ヽ_つ/ // /|( (ヽ| |、\| 丿 \ ⌒)| |  ) /
'ノ )  Lノ*/using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queuetypedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'#define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);const ll oo = 1ll<<17;
const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9+7;
const double esp = 1e-8;
const double PI=acos(-1.0);
const double PHI=0.61803399;    //黄金分割点
const double tPHI=0.38196601;template<typename T>
inline T read(T&x){x=0;int f=0;char ch=getchar();while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x=f?-x:x;
}inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;}/*-----------------------showtime----------------------*/string str[10];map<string ,int>mp;vector<int>G[509];int fa[509],du[509],dig[509];int find(int x) {if(fa[x] == x) return x;return fa[x] = find(fa[x]);}int dfs(int s,int t){int flag = 0;for(int i=0; i<G[s].size(); i++){int v = G[s][i];if(v == t) flag = 1;flag = (flag || dfs(v, t));}return flag;}
int main(){int n,m;scanf("%d%d", &n, &m);int tot = 0;rep(i, 1, 508) fa[i] = i;rep(i, 1, n) {rep(j, 1, 5) cin>>str[j];int u,v;if(mp.count(str[1]))  u = mp[str[1]];else {++tot; u = tot;mp[str[1]] = tot;}if(mp.count(str[5]))  v = mp[str[5]];else {++tot; v = tot;mp[str[5]] = tot;}int fx = find(u), fy = find(v);fa[fx]=  fy;G[u].pb(v);}for(int i=1; i<=m; i++){rep(j, 1, 5) cin>>str[j];if(mp.count(str[1]) == 0 || mp.count(str[5]) == 0) {puts("Pants on Fire");continue;}int u = mp[str[1]];int v = mp[str[5]];if(find(u) != find(v) ) puts("Pants on Fire");else if(dfs(u, v)) puts("Fact");else if(dfs(v, u))puts("Alternative Fact");else puts("Pants on Fire");}return 0;
}
View Code

E Perpetuum Mobile

spfa判正权环

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//headconst int N = 800 + 10;
double d[N];
struct edge {int to;double w;
};
vector<edge> g[N];
bool vis[N];
bool spfa(int u) {vis[u] = true;for (edge v : g[u]) {if(d[u] + v.w < d[v.to]) {d[v.to] = d[u] + v.w;if(vis[v.to]) return true;if(spfa(v.to)) return true;}}vis[u] = false;return false;
}
int main() {int n, m, u, v;double w;scanf("%d %d", &n, &m);for (int i = 1; i <= m; ++i) {scanf("%d %d %lf", &u, &v, &w);g[u].pb({v, -log(w)});}for (int i = 1; i <= n; ++i) d[i] = 0;for (int i = 1; i <= n; ++i) if(spfa(i)) {puts("inadmissible");return 0;}puts("admissible");return 0;
}
View Code

F Plug It In

枚举三个插座的位置,拆点,然后二分图匹配

代码:

#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>/*⊂_ヽ\\ Λ_Λ  来了老弟\('ㅅ')> ⌒ヽ/   へ\/  / \\レ ノ   ヽ_つ/ // /|( (ヽ| |、\| 丿 \ ⌒)| |  ) /
'ノ )  Lノ*/using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queuetypedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'#define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);const ll oo = 1ll<<17;
const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9+7;
const double esp = 1e-8;
const double PI=acos(-1.0);
const double PHI=0.61803399;    //黄金分割点
const double tPHI=0.38196601;template<typename T>
inline T read(T&x){x=0;int f=0;char ch=getchar();while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x=f?-x:x;
}inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;}/*-----------------------showtime----------------------*/const int maxn = 1509;int pt[maxn],vis[maxn];struct node{int cnt;int id;}a[maxn];queue<int>que;vector<int>mp[maxn];int col = 0;bool dfs(int u){if(vis[u] == col) return false;vis[u] = col;for(int i=0; i<mp[u].size(); i++){int v = mp[u][i];if(pt[v] ==0 || dfs(pt[v])) {pt[v] = u;return true;};}return false;}int in[maxn];bool cmp(node a,node b){return a.cnt < b.cnt;}
int main(){int n,m,k;scanf("%d%d%d", &n, &m, &k);rep(i, 1, m) a[i].id = i;for(int i=1; i<=k; i++){int u,v;scanf("%d%d", &u, &v);mp[v].pb(u);a[v].cnt++;}sort(a+1, a+1+m, cmp);int ans = 0;for(int i=1; i<=m; i++) {// memset(vis, 0, sizeof(vis));col++;if(dfs(a[i].id) == 0) que.push(a[i].id);else ans++;}int mx = 0;while(!que.empty()){int u = que.front(); que.pop();for(int i=0; i<mp[u].size(); i++){int v = mp[u][i];in[v]++;mx = max(mx, in[v]);}}mx = min(2, mx);ans += mx;printf("%d\n", ans);return 0;
}
View Code

G Water Testing

皮克定理

代码:

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e6+10;
const int mod=1e9+7;
struct Point{int x;int y;}pa[maxn];
int  Cross(Point A,Point B) { return A.x*B.y-A.y*B.x;   }  // 叉积
/*bool anglecmp(Point a, Point b)
{if(a.y <= 0 && b.y > 0) return true;if(a.y > 0 && b.y <= 0) return false;if(!a.y && !b.y) return a.x < b.x;return Cross(a,b) > 0;
}*/
int work(Point a,Point b)
{return __gcd( abs(a.x-b.x),abs(b.y-a.y) )-1;
}
int32_t main()
{int n; scanf("%lld",&n);for(int i=1;i<=n;i++)  scanf("%lld %lld",&pa[i].x,&pa[i].y);//sort(pa+1,pa+1+n,anglecmp);int ans=0;for(int i=1;i<n;i++)ans+=Cross(pa[i],pa[i+1]);ans+=Cross(pa[n],pa[1]);ans=abs(ans);int x=n;for(int i=1;i<n;i++)x+=work(pa[i],pa[i+1]);x+=work(pa[n],pa[1]);int a=(ans-x+2)/2;printf("%lld\n",a);
}
View Code

H Ratatoskr

枚举根,求最长链,然后取最小

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";const int N = 85;
vector<int> g[N];
int dfs(int u, int o) {int res = 1;for (int v : g[u]) {if(v != o) res = max(res, dfs(v, u)+1);}return res;
}
int main() {int n, a, b, c, u, v;scanf("%d", &n);scanf("%d %d %d", &a, &b, &c);for (int i = 1; i < n; ++i) scanf("%d %d", &u, &v), g[u].pb(v), g[v].pb(u);int ans = n;for (int i = 1; i <= n; ++i) {if(i == b || i == c) ans =min(ans, dfs(i, i)-1);else ans = min(dfs(i, i), ans);}printf("%d\n", ans);return 0;
}
View Code

I Uberwatch

dp

代码:

#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>/*⊂_ヽ\\ Λ_Λ  来了老弟\('ㅅ')> ⌒ヽ/   へ\/  / \\レ ノ   ヽ_つ/ // /|( (ヽ| |、\| 丿 \ ⌒)| |  ) /
'ノ )  Lノ*/using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queuetypedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'#define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);const ll oo = 1ll<<17;
const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9+7;
const double esp = 1e-8;
const double PI=acos(-1.0);
const double PHI=0.61803399;    //黄金分割点
const double tPHI=0.38196601;template<typename T>
inline T read(T&x){x=0;int f=0;char ch=getchar();while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x=f?-x:x;
}inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;}/*-----------------------showtime----------------------*/const int maxn = 3e5+9;int a[maxn],dp[maxn],res[maxn];
int main(){int n,m;scanf("%d%d", &n, &m);rep(i, 1, n) scanf("%d", &a[i]);rep(i, m+1, n) {dp[i] = max(dp[i],res[i-m] + a[i]);res[i] = max(res[i-1], dp[i]);}printf("%d\n", res[n]);return 0;
}
View Code

J Word Clock

旅行商问题变形,状压dp实现

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);const int N = 19;
const int INF = 0x3f3f3f3f;
int h, w, n;
string t[N], s[N];
int d[N][N], up;
pii dp[N][1<<N];
int pre[N][1<<N];
pii dfs(int u, int st) {if(~dp[u][st].fi) return dp[u][st];pii res = {INF, INF};for (int i = 0; i < n; ++i) {if(i == u) continue;if(st & (1<<i)) {pii p = dfs(i, st^(1<<u));p.se += d[i][u];if(p.se > w) p.fi++, p.se = s[u].size();if(p < res) {res = p;pre[u][st] = i;}}}if(res.fi == INF) res.fi = 0, res.se = s[u].size();return dp[u][st] = res;
}
int main() {fio;cin >> h >> w >> n;int tot = 0;for (int i = 0; i < n; ++i) cin >> t[i];for (int i = 0; i < n; ++i) {bool f = true;if(t[i].size() > w) return 0*puts("impossible");for (int j = 0; j < n; ++j) {if(i == j) continue;if(t[j].find(t[i]) == string::npos) continue;f = false;}if(f) s[tot++] = t[i];}n = tot;for (int i = 0; i < n; ++i) {for (int j = 0; j < n; ++j) {if(i == j) continue;int mn = min(s[i].size(), s[j].size());d[i][j] = s[j].size();for (int k = 1; k <= mn; ++k) {if(s[i].substr(s[i].size()-k, k) == s[j].substr(0, k)) d[i][j] = s[j].size() - k; ///!!!!!!!!!
            }}}up = 1<<n;for (int i = 0; i < n; ++i) {for (int j = 0; j < up; ++j)dp[i][j] = {-1, -1}, pre[i][j] = -1;}for (int i = 0; i < n; ++i) {pii p = dfs(i, up-1);if(p.fi < h) {vector<string> res (h, string(w, 'X'));vector<int> p;int now = i, st = up-1;while(~now) {p.pb(now);now = pre[now][st];st ^= 1<<p.back();}reverse(p.begin(), p.end());pii pos = {0, 0};for (int i = 0; i < p.size(); ++i) {int x = p[i];if(i == 0) {for (int j = 0; j < s[x].size(); ++j) res[pos.fi][pos.se+j] = s[x][j];pos.se += s[x].size();}else {int u = p[i-1];if(pos.se + d[u][x] > w) {pos.fi++;pos.se = 0;for (int j = 0; j < s[x].size(); ++j) res[pos.fi][pos.se+j] = s[x][j];pos.se = s[x].size();}else {int sz = s[x].size();for (int j = 0; j < d[u][x]; ++j) res[pos.fi][pos.se+j] = s[x][sz-d[u][x]+j];pos.se += d[u][x];}}}for (int i = 0; i < h; ++i) cout << res[i] << endl;return 0;}}return 0*puts("impossible");
}
View Code

K You Are Fired

排序

代码:

#include <algorithm>
#include  <iterator>
#include  <iostream>
#include   <cstring>
#include   <cstdlib>
#include   <iomanip>
#include    <bitset>
#include    <cctype>
#include    <cstdio>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath>
#include     <queue>
#include      <list>
#include       <map>
#include       <set>
#include   <cassert>/*⊂_ヽ\\ Λ_Λ  来了老弟\('ㅅ')> ⌒ヽ/   へ\/  / \\レ ノ   ヽ_つ/ // /|( (ヽ| |、\| 丿 \ ⌒)| |  ) /
'ノ )  Lノ*/using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queuetypedef long long ll;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3;//priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n'#define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c);const ll oo = 1ll<<17;
const ll mos = 0x7FFFFFFF;  //2147483647
const ll nmos = 0x80000000;  //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //18
const int mod = 1e9+7;
const double esp = 1e-8;
const double PI=acos(-1.0);
const double PHI=0.61803399;    //黄金分割点
const double tPHI=0.38196601;template<typename T>
inline T read(T&x){x=0;int f=0;char ch=getchar();while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x=f?-x:x;
}inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;}/*-----------------------showtime----------------------*/const int maxn = 1e4+9;struct node{string name;ll x;}a[maxn];bool cmp(node a, node b){return a.x > b.x;}
int main(){ll n, d, k;cin>>n>>d>>k;rep(i,1, n){cin>>a[i].name>>a[i].x;}sort(a+1,a+1+n,cmp);ll sum = 0;rep(i,1, k) sum += a[i].x;if(sum < d) puts("impossible");else {printf("%d\n", k);rep(i, 1, k) {cout<<a[i].name<<", YOU ARE FIRED!"<<endl;}}return 0;
}
View Code

转载于:https://www.cnblogs.com/widsom/p/10471536.html

相关文章:

C++11中std::bind的使用

std::bind函数是用来绑定函数调用的某些参数的。std::bind它可以预先把指定可调用实体的某些参数绑定到已有的变量&#xff0c;产生一个新的可调用实体。它绑定的参数的个数不受限制&#xff0c;绑定的具体哪些参数也不受限制&#xff0c;由用户指定。 std::bind&#xff1a;(…

在图数据上做机器学习,应该从哪个点切入?

作者 | David Mack编译 | ronghuaiyang来源 | AI公园&#xff08;ID:AI_Paradise&#xff09;【导读】很多公司和机构都在使用图数据&#xff0c;想在图上做机器学习但不知从哪里开始做&#xff0c;希望这篇文章给大家一点启发。自从我们在伦敦互联数据中心(Connected Data Lon…

C++11中Lambda表达式的使用

Lambda表达式语法&#xff1a;[capture ] ( params ) mutable exception attribute -> return-type { body } 其中capture为定义外部变量是否可见(捕获)&#xff0c;若为空&#xff0c;则表示不捕获所有外部变量&#xff0c;即所有外部变量均不可访问&#xff0c; 表示所有…

倒计时2天 | 专属技术人的盛会,为你而来!

5G 元年&#xff0c;人工智能 60 年&#xff0c;全球AI市场正发生着巨大的变化&#xff0c;顶尖科技企业和创新力量不断地进行着技术的更迭和应用的推进&#xff0c;专属于 AI 开发者的技术盛宴——2019 AI开发者大会&#xff08;AI ProCon&#xff09;将于 2 天后&#xff08;…

了解大数据的特点、来源与数据呈现方式

作业来源&#xff1a;https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2639 浏览2019春节各种大数据分析报告&#xff0c;例如&#xff1a; 这世间&#xff0c;再无第二个国家有能力承载如此庞大的人流量。http://www.sohu.com/a/290025769_313993春节人口迁徙大数据…

Mysql使用大全 从基础到存储过程

平常习惯了phpmyadmin等其他工具的的朋友有的根本就不会命令&#xff0c;如果让你笔试去面试我看你怎么办&#xff0c;所以&#xff0c;学习一下还是非常有用的&#xff0c;也可以知道你通过GUI工具的时候工具到底做了什么。Mysql用处很广&#xff0c;是php最佳拍档&#xff0c…

GDAL库简介以及在Windows下编译过程

GDAL(Geospatial Data Abstraction Library&#xff0c;地理空间数据抽象库)是一个在X/MIT许可协议下的开源栅格空间数据转换库。官网http://www.gdal.org/index.html&#xff0c;也可参考GitHub https://github.com/OSGeo/gdal&#xff0c;最新release版本为2.1.1. GDAL是一个…

Hexo博客NexT主题美化之评论系统

前言 更多效果展示&#xff0c;请访问我的 个人博客。 效果图&#xff1a; Valine 诞生于2017年8月7日&#xff0c;是一款基于Leancloud的快速、简洁且高效的无后端评论系统。 教程&#xff1a; 登录 Leancloud 官网&#xff0c;注册之后创建一个应用&#xff0c;选择【设置】-…

倒计时1天 | 专属技术人的盛会,为你而来!

5G 元年&#xff0c;人工智能 60 年&#xff0c;全球AI市场正发生着巨大的变化&#xff0c;顶尖科技企业和创新力量不断地进行着技术的更迭和应用的推进&#xff0c;专属于 AI 开发者的技术盛宴——2019 AI开发者大会&#xff08;AI ProCon&#xff09;将于 明天&#xff08;9 …

Selenium 2 WebDriver 多线程 并发

我用的是Selenium2&#xff0c;至于它的背景和历史就不赘述了。Selenium2也叫WebDriver。下面讲个例子&#xff0c;用WebDriverjava来写个自动化测试的程序。&#xff08;如果能用firefox去测试的话&#xff0c;我就直接用Selenium IDE录脚本了。。。&#xff09;有个前提&…

GDAL2.1.1库在Ubuntu14.04下编译时遇到的问题处理方法

不用作任何调整&#xff0c;直接在Linux下编译GDAL2.1.1源码的步骤是&#xff1a;$ ./configure $ make $ make install非常简单&#xff0c; 这样也能正常生成gdal动态库、静态库&#xff0c;如果想将生成的文件放到指定的目录&#xff0c;则需改第一条命令为&#xff1a;$ ./…

刷爆了!这项技术BAT力捧!程序员:我彻底慌了...

人工智能离我们还遥远吗&#xff1f;近日&#xff0c;海底捞斥资1.5亿打造了中国首家火锅无人餐厅&#xff1b;阿里酝酿了两年之久的全球首家无人酒店也正式开始运营&#xff0c;百度无人车彻底量产。李彦宏称&#xff0c;这是中国第一款能够量产的无人驾驶乘用车。而阿里的这家…

redux的compose源码,中文注释

用图片会更清楚一点,注释和代码会分的清楚源码解析参考请参考https://segmentfault.com/a/11...

做好职业规划:做自己的船长

要想在职场上有所斩获&#xff0c;就必须做好职业规划。对于职场中人来说&#xff0c;职业规划是职业发展中最关键的向导。职业规划因人而异&#xff0c;不同的对象有不同的需求&#xff0c;因此制定的目标与计划也不尽相同&#xff0c;但个人为自己做职业规划的方法和流程是大…

GDAL中GDALDataset::RasterIO分块读取的实现

GDALDataset类中的RasterIO函数能够对图像任意指定区域、任意波段的数据按指定数据类型、指定排列方式读入内存和写入文件中&#xff0c;因此可以实现对大影像的分块读、写运算操作。针对特大的影像图像&#xff0c;有时为了减少内存消耗&#xff0c;对图像进行分块读取很有必要…

掌握深度学习,为什么要用PyTorch、TensorFlow框架?

作者 | Martin Heller译者 | 弯月责编 | 屠敏来源 | CSDN&#xff08;ID&#xff1a;CSDNnews&#xff09;【导读】如果你需要深度学习模型&#xff0c;那么 PyTorch 和 TensorFlow 都是不错的选择。并非每个回归或分类问题都需要通过深度学习来解决。甚至可以说&#xff0c;并…

ICANN敦促业界使用DNSSEC,应对DNS劫持攻击

HTTPS加密 可以有效帮助服务器应对DNS欺骗、DNS劫持、ARP攻击等安全威胁。DNS是什么&#xff1f;DNS如何被利用&#xff1f;HTTPS如何防止DNS欺骗&#xff1f; DNS如何工作&#xff1f; 如果您想访问www.example.com&#xff0c;您的浏览器需要找到该特定Web服务器的IP地址。它…

Lucene.net: the main concepts

2019独角兽企业重金招聘Python工程师标准>>> In the previous post you learnt how to get a copy of Lucene.net and where to go in order to look for more information. As you noticed the documentation is far from being complete and easy to read. So in …

einsum,一个函数走天下

作者 | 永远在你身后转载自知乎【导读】einsum 全称 Einstein summation convention&#xff08;爱因斯坦求和约定&#xff09;&#xff0c;又称为爱因斯坦标记法&#xff0c;是爱因斯坦 1916 年提出的一种标记约定&#xff0c;本文主要介绍了einsum 的应用。简单的说&#xff…

常用排序算法的C++实现

排序是将一组”无序”的记录序列调整为”有序”的记录序列。假定在待排序的记录序列中&#xff0c;存在多个具有相同的关键字的记录&#xff0c;若经过排序&#xff0c;这些记录的相对次序保持不变&#xff0c;即在原序列中&#xff0c;rirj&#xff0c;且ri在rj之前&#xff0…

4.65FTP服务4.66测试登录FTP

2019独角兽企业重金招聘Python工程师标准>>> FTP服务 测试登录FTP 4.65FTP服务 文件传输协议&#xff08;FTP&#xff09;&#xff0c;可以上传和下载文件。比如我们可以把Windows上的文件shan上传到Linux&#xff0c;也可以把Linux上的文件下载到Windows上。 Cent…

JavaScript的应用

DOM, BOM, XMLHttpRequest, Framework, Tool (Functionality) Performance (Caching, Combine, Minify, JSLint) ---------------- 人工做不了&#xff0c;交给程序去做&#xff0c;这样可以流程化。 Maintainability (Pattern) http://www.jmarshall.com/easy/http/ http://dj…

miniz库简介及使用

miniz&#xff1a;Google开源库&#xff0c;它是单一的C源文件&#xff0c;紧缩/膨胀压缩库&#xff0c;使用zlib兼容API&#xff0c;ZIP归档读写&#xff0c;PNG写方式。关于miniz的更详细介绍可以参考&#xff1a;https://code.google.com/archive/p/miniz/miniz.c is a loss…

iOS之runtime详解api(三)

第一篇我们讲了关于Class和Category的api&#xff0c;第二篇讲了关于Method的api&#xff0c;这一篇来讲关于Ivar和Property。 4.objc_ivar or Ivar 首先&#xff0c;我们还是先找到能打印出Ivar信息的函数&#xff1a; const char * _Nullable ivar_getName(Ivar _Nonnull v) …

亚马逊首席科学家李沐「实训营」国内独家直播,马上报名 !

开学了&#xff0c;别人家的学校都开始人工智能专业的学习之旅了&#xff0c;你呢&#xff1f;近年来&#xff0c;国内外顶尖科技企业的 AI 人才抢夺战愈演愈烈。华为开出200万年薪吸引 AI 人才&#xff0c;今年又有 35 所高校新增人工智能本科专业&#xff0c;众多新生即将开展…

人脸检测库libfacedetection介绍

libfacedetection是于仕琪老师放到GitHub上的二进制库&#xff0c;没有源码&#xff0c;它的License是MIT&#xff0c;可以商用。目前只提供了windows 32和64位的release动态库&#xff0c;主页为https://github.com/ShiqiYu/libfacedetection&#xff0c;采用的算法好像是Mult…

倒计时1天 | 2019 AI ProCon报名通道即将关闭(附参会指南)

2019年9月5-7日&#xff0c;面向AI技术人的年度盛会—— 2019 AI开发者大会 AI ProCon&#xff0c;震撼来袭&#xff01;2018 年由 CSDN 成功举办 AI 开发者大会一年之后&#xff0c;全球 AI 市场正发生着巨大的变化。顶尖科技企业和创新力量不断地进行着技术的更迭和应用的推…

法院判决:优步无罪,无人车安全员可能面临过失杀人控诉

据路透社报道&#xff0c;负责优步无人车在亚利桑那州致人死亡事件调查的律师事务所发布公开信宣布&#xff0c;优步在事故中“不承担刑事责任”&#xff0c;但是当时在车上的安全员Rafaela Vasquez要接受进一步调查&#xff0c;可能面临车辆过失杀人罪指控。2018年3月&#xf…

09 Storage Structure and Relationships

目标&#xff1a;存储结构&#xff1a;Segments分类&#xff1a;Extents介绍&#xff1a;Blocks介绍&#xff1a;转载于:https://blog.51cto.com/eread/1333894