A. Anti-knapsack
思路:首先比k大的都可以加进来。其次对于小于k的,检验当前集合里面有没有和他相加等于k的,没有的话就可以加进集合。这一步可以覆盖多个数相加的情况。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '
'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), k = read();
vector<ll> ans;
rep(i,k+1, n) ans.pb(i);
per(i,k-1, 1)
{
int flag = 1;
for(int j=0; j<ans.size(); j++)
{
if(ans[j] + i == k)
{
flag = 0;
break;
}
}
if(flag) ans.pb(i);
}
cout<<ans.size()<<endl;
for(int i=0; i<ans.size(); i++) cout<<ans[i]<<' '; cout<<endl;
}
return 0;
}
B. Planet Lapituletti
思路:逐位模拟即可,注意一下细节。检验的时候注意:
1.镜像完肯定要是一个数字,满足的只有0->0, 1->1, 2->5, 5->2, 8->8。
2.镜像完分钟位和小时位是互换的。
详见代码
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '
'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll h, m;
map<ll,ll> Map;
PII nextTime(PII cur)
{
ll e = 0;
ll hour = cur.fi;
ll mi = cur.se;
mi += 1;
if(mi>=m) mi = 0, e = 1;
hour += e;
if(hour>=h) hour = 0;
PII ans;
ans.fi = hour;
ans.se = mi;
return ans;
}
bool check(PII cur)
{
ll hour = cur.fi;
ll mi = cur.se;
vector<ll> mirrorMi;
vector<ll> mirrorH;
while(mi) mirrorMi.pb(mi%10), mi /= 10;
while(mirrorMi.size()<2) mirrorMi.pb(0);
while(hour) mirrorH.pb(hour%10), hour /= 10;
while(mirrorH.size()<2) mirrorH.pb(0);
int flag = 1;
for(int i=0; i<mirrorMi.size(); i++) if(mirrorMi[i]!=0&&!Map[mirrorMi[i]]) flag = 0;
for(int i=0; i<mirrorH.size(); i++) if(mirrorH[i]!=0&&!Map[mirrorH[i]]) flag = 0;
if(!flag) return false;
ll curM = Map[mirrorH[0]]*10+Map[mirrorH[1]];
ll curH = Map[mirrorMi[0]]*10 + Map[mirrorMi[1]];
if(curH<h&&curM<m) return true;
return false;
}
int main()
{
Map[0] = 0;
Map[1] = 1;
Map[2] = 5;
Map[5] = 2;
Map[8] = 8;
int kase;
cin>>kase;
while(kase--)
{
h = read(), m = read();
PII cur;
scanf("%lld:%lld",&cur.fi, &cur.se);
while(1)
{
if(check(cur)) break;
cur = nextTime(cur);
}
printf("%02lld:%02lld
",cur.fi,cur.se);
}
return 0;
}