Drawing Borders

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

代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
struct Point{ int x,y; };
Point a[maxn]; int numa=;
Point b[maxn]; int numb=;
vector<pair<double,double> > va;
vector<pair<double,double> > vb;
void checka()
{
va.push_back({,});
va.push_back({,});
for(int i=numa;i>=;i--)
{
va.push_back( { a[i].x*1.000-0.3,} );
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->= && a[i-].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,-} );
va.push_back( {a[i].x*1.0000-0.39,-} );
va.push_back( {a[i].x*1.0000-0.39,});
}
va.push_back({-,});
va.push_back({-,});
}
void checkb()
{
vb.push_back({-,-});
vb.push_back({-,-});
for(int i=;i<=numb;i++)
{
vb.push_back( { b[i].x*1.000+0.3,-} ); 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+<=numb && b[i+].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,} );
vb.push_back( { b[i].x*1.000+0.39,} );
vb.push_back( { b[i].x*1.000+0.39,-} );
}
vb.push_back({,-});
vb.push_back({,-});
}
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=;i<=n;i++)
{
int x,y,z; scanf("%d %d %d",&x,&y,&z);
if(z==) a[++numa].x=x,a[numa].y=y;
if(z==) b[++numb].x=x,b[numb].y=y;
}
sort(a+,a++numa,upa); checka();
sort(b+,b++numb,upb); checkb();
printf("%d\n",va.size()); for(int i=;i<va.size();i++) printf("%.4f %.4f\n",va[i].first,va[i].second);
printf("%d\n",vb.size()); for(int i=;i<vb.size();i++) printf("%.4f %.4f\n",vb[i].first,vb[i].second);
}

Buildings

polya定理

代码:

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

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);
//head const int N = 1e3 + ;
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 == && m == x) return dp[u][m] = ;
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, -);
scanf("%d", &x);
scanf("%d %d %d", &n, &m, &T);
for (int i = ; i <= m; ++i) scanf("%d %d", &u, &v), g[u].pb(v), g[v].pb(u);
for (int i = ; i <= n; ++i) scanf("%d %d", &t[i], &p[i]);
LL tmp = dfs(, t[]) + p[];
if(t[]* > x || tmp >= INF) printf("It is a trap.\n");
else printf("%lld\n", tmp);
return ;
}

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_queue typedef 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<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
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=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',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[];
map<string ,int>mp;
vector<int>G[];
int fa[],du[],dig[];
int find(int x) {
if(fa[x] == x) return x;
return fa[x] = find(fa[x]);
}
int dfs(int s,int t){
int flag = ;
for(int i=; i<G[s].size(); i++){
int v = G[s][i];
if(v == t) flag = ;
flag = (flag || dfs(v, t));
}
return flag;
}
int main(){
int n,m;
scanf("%d%d", &n, &m);
int tot = ;
rep(i, , ) fa[i] = i;
rep(i, , n) {
rep(j, , ) cin>>str[j];
int u,v;
if(mp.count(str[])) u = mp[str[]];
else {
++tot; u = tot;
mp[str[]] = tot;
} if(mp.count(str[])) v = mp[str[]];
else {
++tot; v = tot;
mp[str[]] = tot;
} int fx = find(u), fy = find(v);
fa[fx]= fy;
G[u].pb(v);
} for(int i=; i<=m; i++){
rep(j, , ) cin>>str[j];
if(mp.count(str[]) == || mp.count(str[]) == ) {
puts("Pants on Fire");
continue;
}
int u = mp[str[]];
int v = mp[str[]];
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 ;
}

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);
//head const int N = + ;
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 = ; i <= m; ++i) {
scanf("%d %d %lf", &u, &v, &w);
g[u].pb({v, -log(w)});
}
for (int i = ; i <= n; ++i) d[i] = ;
for (int i = ; i <= n; ++i) if(spfa(i)) {
puts("inadmissible");
return ;
}
puts("admissible");
return ;
}

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_queue typedef 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<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
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=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',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 = ;
int pt[maxn],vis[maxn];
struct node{
int cnt;
int id;
}a[maxn];
queue<int>que;
vector<int>mp[maxn];
int col = ;
bool dfs(int u){
if(vis[u] == col) return false;
vis[u] = col;
for(int i=; i<mp[u].size(); i++){
int v = mp[u][i];
if(pt[v] == || 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, , m) a[i].id = i;
for(int i=; i<=k; i++){
int u,v;
scanf("%d%d", &u, &v);
mp[v].pb(u);
a[v].cnt++;
} sort(a+, a++m, cmp);
int ans = ;
for(int i=; i<=m; i++) {
// memset(vis, 0, sizeof(vis));
col++;
if(dfs(a[i].id) == ) que.push(a[i].id);
else ans++;
}
int mx = ;
while(!que.empty()){
int u = que.front(); que.pop();
for(int i=; i<mp[u].size(); i++)
{
int v = mp[u][i];
in[v]++;
mx = max(mx, in[v]);
}
}
mx = min(, mx);
ans += mx;
printf("%d\n", ans);
return ;
}

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+;
const int mod=1e9+;
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) )-;
}
int32_t main()
{
int n; scanf("%lld",&n);
for(int i=;i<=n;i++) scanf("%lld %lld",&pa[i].x,&pa[i].y);
//sort(pa+1,pa+1+n,anglecmp);
int ans=;
for(int i=;i<n;i++)
ans+=Cross(pa[i],pa[i+]);
ans+=Cross(pa[n],pa[]);
ans=abs(ans);
int x=n;
for(int i=;i<n;i++)
x+=work(pa[i],pa[i+]);
x+=work(pa[n],pa[]);
int a=(ans-x+)/;
printf("%lld\n",a);
}

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 = ;
vector<int> g[N];
int dfs(int u, int o) {
int res = ;
for (int v : g[u]) {
if(v != o) res = max(res, dfs(v, u)+);
}
return res;
}
int main() {
int n, a, b, c, u, v;
scanf("%d", &n);
scanf("%d %d %d", &a, &b, &c);
for (int i = ; i < n; ++i) scanf("%d %d", &u, &v), g[u].pb(v), g[v].pb(u);
int ans = n;
for (int i = ; i <= n; ++i) {
if(i == b || i == c) ans =min(ans, dfs(i, i)-);
else ans = min(dfs(i, i), ans);
}
printf("%d\n", ans);
return ;
}

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_queue typedef 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<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
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=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',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+;
int a[maxn],dp[maxn],res[maxn];
int main(){
int n,m;
scanf("%d%d", &n, &m);
rep(i, , n) scanf("%d", &a[i]); rep(i, m+, n) {
dp[i] = max(dp[i],res[i-m] + a[i]);
res[i] = max(res[i-], dp[i]);
}
printf("%d\n", res[n]);
return ;
}

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 = ;
const int INF = 0x3f3f3f3f;
int h, w, n;
string t[N], s[N];
int d[N][N], up;
pii dp[N][<<N];
int pre[N][<<N];
pii dfs(int u, int st) {
if(~dp[u][st].fi) return dp[u][st];
pii res = {INF, INF};
for (int i = ; i < n; ++i) {
if(i == u) continue;
if(st & (<<i)) {
pii p = dfs(i, st^(<<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 = , res.se = s[u].size();
return dp[u][st] = res;
}
int main() {
fio;
cin >> h >> w >> n;
int tot = ;
for (int i = ; i < n; ++i) cin >> t[i];
for (int i = ; i < n; ++i) {
bool f = true;
if(t[i].size() > w) return *puts("impossible");
for (int j = ; 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 = ; i < n; ++i) {
for (int j = ; 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 = ; k <= mn; ++k) {
if(s[i].substr(s[i].size()-k, k) == s[j].substr(, k)) d[i][j] = s[j].size() - k; ///!!!!!!!!!
}
}
}
up = <<n;
for (int i = ; i < n; ++i) {
for (int j = ; j < up; ++j)
dp[i][j] = {-, -}, pre[i][j] = -;
}
for (int i = ; i < n; ++i) {
pii p = dfs(i, up-);
if(p.fi < h) {
vector<string> res (h, string(w, 'X'));
vector<int> p;
int now = i, st = up-;
while(~now) {
p.pb(now);
now = pre[now][st];
st ^= <<p.back();
}
reverse(p.begin(), p.end());
pii pos = {, };
for (int i = ; i < p.size(); ++i) {
int x = p[i];
if(i == ) {
for (int j = ; j < s[x].size(); ++j) res[pos.fi][pos.se+j] = s[x][j];
pos.se += s[x].size();
}
else {
int u = p[i-];
if(pos.se + d[u][x] > w) {
pos.fi++;
pos.se = ;
for (int j = ; 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 = ; 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 = ; i < h; ++i) cout << res[i] << endl;
return ;
}
}
return *puts("impossible");
}

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_queue typedef 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<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+;
const double esp = 1e-;
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=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',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+;
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,, n)
{
cin>>a[i].name>>a[i].x;
}
sort(a+,a++n,cmp); ll sum = ;
rep(i,, k) sum += a[i].x;
if(sum < d) puts("impossible");
else {
printf("%d\n", k);
rep(i, , k) {
cout<<a[i].name<<", YOU ARE FIRED!"<<endl;
} }
return ;
}

2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)的更多相关文章

  1. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  2. 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)(9/11)

    $$2017-2018\ ACM-ICPC\ German\ Collegiate\ Programming\ Contest (GCPC 2017)$$ \(A.Drawing\ Borders\) ...

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

    A. Drawing Borders Unsolved. B. Buildings Unsolved. C. Joyride Upsolved. 题意: 在游乐园中,有n个游玩设施,有些设施之间有道路 ...

  4. 2018 German Collegiate Programming Contest (GCPC 18)

    2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...

  5. (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)

    layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...

  6. 2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3(12/13)

    $$2015\ German\ Collegiate\ Programming\ Contest\ (GCPC 15) + POI 10-T3$$ \(A.\ Journey\ to\ Greece\ ...

  7. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  8. ACM ICPC, Amman Collegiate Programming Contest (2018) Solution

    Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...

  9. Gym .102021 .German Collegiate Programming Contest (GCPC 18) (寒假gym自训第三场)

    B .Battle Royale 题意:给你两个点A,B,以及一个圆S,保证两个点在圆外,且其连线与圆相交,求两点间最短距离. 思路:显然是要分别与圆相切,然后在圆弧想走,直到相交. 那么ans=与圆 ...

随机推荐

  1. setup FTP server on CentOS 7

    Setup FTP Server on CentOS 7 Install vsftpd vsftpd (Very Secure File Transport Protocol Daemon) is a ...

  2. DS18B20初上电显示85℃问题

    以前用的温度采集都是用的AD,这次改为了DS18B20,看了资料,没有很复杂的部分,重要的就是时序.板子出来后初步测试也能正常读取温度,然而有个问题比较奇怪,就是在板子初上电时读取温度总是显示为+85 ...

  3. Git知识

    git最小化配置: 配置user.name 和 user.email git config --global user.name 'your_name' git config --global use ...

  4. upCode

    更新源码 Sub main() Dim str As String str = "这是测试的字符串对话框" MsgBox str Sheets(1).Select End Sub

  5. Python语言——基础02-变量、运算符

    开篇导言: 今天开始进行python学习的笔记更新,以后我都用截图的方式更新,方便不麻烦,界面美观,今天学习更新的python学习内容是环境变量.运算符的内容 关注我博客的童鞋从现在开始也可以跟着我的 ...

  6. centos7 lamp

    yum install libmcrypt libmcrypt-devel mcrypt mhash zlib zlib-devel libpng libpng-devel freetype free ...

  7. Halcon 和 C# 联合编程 - 图像变量的相互转换(HObject、HImage、Bitmap)

    /// <summary> /// 灰度图像 HObject -> Bitmap /// </summary> public static Bitmap HObject2 ...

  8. react问题解决的一些方法

    原文链接: https://segmentfault.com/a/1190000007811296?utm_source=tuicool&utm_medium=referral 初学者对Rea ...

  9. c++算法实现(一) - 递归和初始化

    递归 写递归函数经常出错,提醒自己两个规则: 1. 一般来说递归函数中不应该出现for.while之类的循环语句, 因为递归就是循环的另外一种实现: 2. 注意基线条件,具体参考<算法图解> ...

  10. Hadoop 安全模式safemode

    启动Hdfs 系统的时候,其中的一个阶段“”安全模式 发生阶段:NameNode启动中,已经读取了fsimage 并且生成了edits 文件,在等待dataNode 向nameNode 发送block ...