2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)
很多构造方法,下图可能是最简单的了
代码:
#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);
}
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;
}
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);
//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 ;
}
拓扑排序
代码:
#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 ;
}
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 ;
}
枚举三个插座的位置,拆点,然后二分图匹配
代码:
#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 ;
}
皮克定理
代码:
#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);
}
枚举根,求最长链,然后取最小
代码:
#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 ;
}
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 ;
}
旅行商问题变形,状压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");
}
排序
代码:
#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)的更多相关文章
- (寒假开黑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 ...
- 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\) ...
- 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) Solution
A. Drawing Borders Unsolved. B. Buildings Unsolved. C. Joyride Upsolved. 题意: 在游乐园中,有n个游玩设施,有些设施之间有道路 ...
- 2018 German Collegiate Programming Contest (GCPC 18)
2018 German Collegiate Programming Contest (GCPC 18) Attack on Alpha-Zet 建树,求lca 代码: #include <al ...
- (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)
layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...
- 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\ ...
- ACM ICPC, JUST Collegiate Programming Contest (2018) Solution
A:Zero Array 题意:两种操作, 1 p v 将第p个位置的值改成v 2 查询最少的操作数使得所有数都变为0 操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...
- ACM ICPC, Amman Collegiate Programming Contest (2018) Solution
Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...
- Gym .102021 .German Collegiate Programming Contest (GCPC 18) (寒假gym自训第三场)
B .Battle Royale 题意:给你两个点A,B,以及一个圆S,保证两个点在圆外,且其连线与圆相交,求两点间最短距离. 思路:显然是要分别与圆相切,然后在圆弧想走,直到相交. 那么ans=与圆 ...
随机推荐
- (转)测试如何区别是前端的问题还是后台的bug
常常说到的一个IT项目,包括前端开发,后台开发,软件测试,架构,项目经理,产品需求.那么对于一位优秀的软件测试工程师来说,需要区分前端和后台的工作就显得尤为重要. - 什么是前端和后台 简而言之,前端 ...
- ELK日志分析解决方案
概要 ELK(Elasticsearch , Logstash, Kibana的简称)是目前比较流行的日志分析解决方案,核心包括了三个部分 Elasticsearch:日志查询分析引擎 Logstas ...
- 再次聊一聊promise settimeout asycn awiat执行顺序---js执行机制 EVENT LOOP
首先js是单线程 分为同步和异步,异步又分为(macrotask 宏任务 和 microtask微任务 ), 这图还是很清晰嘛,再来一张 总结一下,就是遇到同步先执行同步,异步的丢到一边依次排队,先排 ...
- bootstrap表格添加按钮、模态框实现
bootstrap表格添加按钮.模态框实现 原创 2017年07月20日 17:35:48 标签: bootstrap 1723 bootstrap表格添加按钮.模态框实现 - 需求: 需要表格后面每 ...
- 关于element-ui表格table设置header-cell-class-name样式不起作用的原因分析
在编写表格的时候想给表头添加样式,使用 header-cell-class-name怎么都添加不上样式,检查元素发现连class都没添加上,查了很多资料有人说element之前版本不支持这属性,但我使 ...
- Oracle 中 编写 function 和 procedure 的注意事项
create or replace function sum_pro( v_a number, v_b number ) return number is -- v_result number(10) ...
- validationEngine 使用
引入文件 环境在 jQuery 下 , 所有先要引入 jQuery <%--校验样式--%> <link rel="stylesheet" href=" ...
- CentOS7.3安装zimbra8.7.11
系统版本:CentOS7.3 Zimbra版本:8.7.11 设置IP地址 vi /etc/sysconfig/network-scripts/ifcfg-ens33 #使用vi命令修改ip BOOT ...
- Android SDK Manager for Mac 在线更新镜像地址截至2017-10-01亲测有效
虽然国内google被墙了,但仍可利用国内的某些镜像网站实现Android SDK在线更新,使用方法如下: 1.启动 Android SDK Manager ,打开主界面,依次选择『Tools』.『O ...
- webServices接口开发过程中项目启动遇到的错误org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 422; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-bean
org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 422; schema_reference.4: Failed to read ...