很多构造方法,下图可能是最简单的了
代码:
#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 ;
}