重庆 建站 价格,商城网站建设策划方案,人人设计网主页,莱芜金点子信息港厂房出租K
K Co-prime Permutation
题意#xff1a;给定n和k#xff0c;让你构造n的排列#xff0c;满足gcd(pi, i)1的个数为k。
思路#xff1a;因为x和x-1互质#xff0c;1和任何数互质#xff0c;任何数和它本身不互质
当k为奇数时#xff0c;p11#xff0c;后面k-1个数…K
K Co-prime Permutation
题意给定n和k让你构造n的排列满足gcd(pi, i)1的个数为k。
思路因为x和x-1互质1和任何数互质任何数和它本身不互质
当k为奇数时p11后面k-1个数两两互换
当k为偶数时后面k个数两两互换
#include bits/stdc.h
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define PII pairint,int
typedef long long ll;
const int N1e610;
const int inf0x3f3f3f3f;using namespace std;
int n,k;
int a[N];
void solve()
{cinnk;if(k0){cout-1\n;return ;}int cnt0;for(int i1;in;i) a[i]i;if(k1){cnt1;for(int i2;incntk;i){if(cnt1) a[i]i1;else a[i]i-1;cnt;}}else{for(int i1;incntk;i){if(cnt%20) a[i]i1;else a[i]i-1;cnt;}}for(int i1;in;i)couta[i] \n[in];
}
signed main()
{//freopen(input.txt,r,stdin);//freopen(output.txt,w,stdout);ios;int _t1;
// cin_t;while(_t--) solve();system(pause);return 0;
}
L
Lets Play Curling
题意给定n块红色石头m块蓝色石头的位置。记红色石头的位置为a[i]蓝色石头的位置为b[i]。当红色石头到目标位置c的距离比蓝色所有石头到目标位置的距离都要小时计一分找到一个c点可以让红队尽可能多赢输出红队尽可能多赢的次数。
思路在两块蓝色石头之间一定存在一个位置满足条件得分为两个蓝色石头之间红色石头的个数。
即求两个蓝色石头之间最多有几个红色石头。
排序后枚举蓝色石头的位置p二分红色石头找到上下界。
#include bits/stdc.h
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define PII pairint,int
typedef long long ll;
const int N1e610;
const int inf0x3f3f3f3f;using namespace std;
int n,m;
void solve()
{cinnm;vectorinta,b;for(int i1;in;i){int x;cinx;a.push_back(x);}for(int i1;im;i){int x;cinx;b.push_back(x);}b.push_back(0);b.push_back(1e910);sort(a.begin(),a.end());sort(b.begin(),b.end());int ans0;for(int i0;im;i){int lupper_bound(a.begin(),a.end(),b[i])-a.begin();int rlower_bound(a.begin(),a.end(),b[i1])-a.begin();ansmax(ans,r-l);}if(ans0) coutImpossible\n;else coutans\n;
}
signed main()
{//freopen(input.txt,r,stdin);//freopen(output.txt,w,stdout);ios;int _t1;cin_t;while(_t--) solve();system(pause);return 0;
}
E
Evil Coordinate
题意初始位置为(0, 0)给定陷阱位置(x, y)和操作字符串。让我们重排列操作字符串使得不陷入陷阱。
思路设最终位置为(X, Y)若有解则(X, Y)与(x, y)至少有一维坐标不同我们可以先走不同的那个方向再走相同的那个方向。所以我们可以将相同操作排在一起然后枚举UDLR的全排列就可以。
#include bits/stdc.h
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define PII pairint,int
typedef long long ll;
const int N1e610;
const int inf0x3f3f3f3f;using namespace std;
int x,y;
string s;
int dir[4][2]{0,1,0,-1,-1,0,1,0};
char op[4]{U,D,L,R};
mapint,intcnt;
string ans;
bool check(vectorintv)
{ans.clear();int X0,Y0;for(int i0;i4;i){for(int j0;jcnt[v[i]];j){ansop[v[i]];Xdir[v[i]][0];Ydir[v[i]][1];if(XxYy) return 0;}}return 1;
}
void solve()
{cinxy;cins;if(x0y0){coutImpossible\n;return ;}cnt.clear();for(int i0;is.length();i)if(s[i]U) cnt[0];else if(s[i]D) cnt[1];else if(s[i]L) cnt[2];else cnt[3];vectorintv{0,1,2,3};bool f0;do{if(check(v)){f1;break;}} while (next_permutation(v.begin(),v.end()));if(!f){coutImpossible\n;return ;}else coutans\n;
}
signed main()
{//freopen(input.txt,r,stdin);//freopen(output.txt,w,stdout);//ios;int _t1;cin_t;while(_t--) solve();system(pause);return 0;
}
F
Fireworks
题意小明做一个烟花花费n的时间点燃所有做好的烟花花费m的时间。每个烟花有的概率是完美的。求最优策略下最小时间花费。
思路假设最优策略是每生产k个再一起点燃那么释放一次成功的概率为1-(1-p)^k (pp*1e-4).
释放几次后得到完美的期望满足几何分布。
几何分布在n次伯努利试验中 试验k次才得到第一次成功的概率。详细的说是前k-1次皆失败 第k次成功的概率。 期望E(x)1/p;(概率论公式不再赘述)
那么答案为E(x)*(nkm) (nkm) / [1-(1-p)^k]
接下来三分寻找答案的最小值。
#include bits/stdc.h
#define ios ios::sync_with_stdio(0),cin.tie(0)
#define PII pairint,int
typedef long long ll;
const int N1e610;
const int inf0x3f3f3f3f;using namespace std;
double n,m;
double p;
double qmi(double a,int k)
{double ret1;while(k){if(k1) retret*a;k1;aa*a;}return ret;
}
double get(int k)
{double t1.0-qmi(1.0-p,k);if(t0) return (double)0x3f3f3f3f;return (k*n*1.0m)/t;
}
void solve()
{cinnmp;pp*1e-4;double ans(double)0x3f3f3f3f3f3f3f3f;int l1,r1e9;while(rl){int lmidl(r-l)/3,rmidr-(r-l)/3;double f1get(lmid),f2get(rmid);ansmin(ans,min(f1,f2));if(f1f2) rrmid-1;else llmid1;}printf(%.10f\n,ans);
}
signed main()
{//freopen(input.txt,r,stdin);//freopen(output.txt,w,stdout);//ios;int _t1;cin_t;while(_t--) solve();system(pause);return 0;
}
文章转载自: http://www.morning.kkjhj.cn.gov.cn.kkjhj.cn http://www.morning.rggky.cn.gov.cn.rggky.cn http://www.morning.zzfjh.cn.gov.cn.zzfjh.cn http://www.morning.lgtzd.cn.gov.cn.lgtzd.cn http://www.morning.nypgb.cn.gov.cn.nypgb.cn http://www.morning.nyzmm.cn.gov.cn.nyzmm.cn http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn http://www.morning.tlfzp.cn.gov.cn.tlfzp.cn http://www.morning.jwskq.cn.gov.cn.jwskq.cn http://www.morning.gywfp.cn.gov.cn.gywfp.cn http://www.morning.yhpq.cn.gov.cn.yhpq.cn http://www.morning.rongxiaoman.com.gov.cn.rongxiaoman.com http://www.morning.dwztj.cn.gov.cn.dwztj.cn http://www.morning.bsghk.cn.gov.cn.bsghk.cn http://www.morning.sfwd.cn.gov.cn.sfwd.cn http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn http://www.morning.mqwdh.cn.gov.cn.mqwdh.cn http://www.morning.yrbq.cn.gov.cn.yrbq.cn http://www.morning.mkrjf.cn.gov.cn.mkrjf.cn http://www.morning.fkyqt.cn.gov.cn.fkyqt.cn http://www.morning.hprmg.cn.gov.cn.hprmg.cn http://www.morning.zfwjh.cn.gov.cn.zfwjh.cn http://www.morning.yfnjk.cn.gov.cn.yfnjk.cn http://www.morning.mhnb.cn.gov.cn.mhnb.cn http://www.morning.trffl.cn.gov.cn.trffl.cn http://www.morning.ldhbs.cn.gov.cn.ldhbs.cn http://www.morning.ztdlp.cn.gov.cn.ztdlp.cn http://www.morning.sqqds.cn.gov.cn.sqqds.cn http://www.morning.wrlxt.cn.gov.cn.wrlxt.cn http://www.morning.hfytgp.cn.gov.cn.hfytgp.cn http://www.morning.ndyrb.com.gov.cn.ndyrb.com http://www.morning.ctlzf.cn.gov.cn.ctlzf.cn http://www.morning.lpmjr.cn.gov.cn.lpmjr.cn http://www.morning.clgbb.cn.gov.cn.clgbb.cn http://www.morning.nwtmy.cn.gov.cn.nwtmy.cn http://www.morning.yfcbf.cn.gov.cn.yfcbf.cn http://www.morning.yrnyz.cn.gov.cn.yrnyz.cn http://www.morning.cwzzr.cn.gov.cn.cwzzr.cn http://www.morning.qmrsf.cn.gov.cn.qmrsf.cn http://www.morning.mrfbp.cn.gov.cn.mrfbp.cn http://www.morning.tgqzp.cn.gov.cn.tgqzp.cn http://www.morning.ymbqr.cn.gov.cn.ymbqr.cn http://www.morning.tqlhn.cn.gov.cn.tqlhn.cn http://www.morning.xlndf.cn.gov.cn.xlndf.cn http://www.morning.ysllp.cn.gov.cn.ysllp.cn http://www.morning.dswtz.cn.gov.cn.dswtz.cn http://www.morning.ssgqc.cn.gov.cn.ssgqc.cn http://www.morning.tbplf.cn.gov.cn.tbplf.cn http://www.morning.txjrc.cn.gov.cn.txjrc.cn http://www.morning.zmbzl.cn.gov.cn.zmbzl.cn http://www.morning.ckntb.cn.gov.cn.ckntb.cn http://www.morning.nhbhc.cn.gov.cn.nhbhc.cn http://www.morning.fhyhr.cn.gov.cn.fhyhr.cn http://www.morning.fnpyk.cn.gov.cn.fnpyk.cn http://www.morning.fplqh.cn.gov.cn.fplqh.cn http://www.morning.xlclj.cn.gov.cn.xlclj.cn http://www.morning.krnzm.cn.gov.cn.krnzm.cn http://www.morning.ldsgm.cn.gov.cn.ldsgm.cn http://www.morning.hbpjb.cn.gov.cn.hbpjb.cn http://www.morning.wrbnh.cn.gov.cn.wrbnh.cn http://www.morning.mrncd.cn.gov.cn.mrncd.cn http://www.morning.zhmgcreativeeducation.cn.gov.cn.zhmgcreativeeducation.cn http://www.morning.nfyc.cn.gov.cn.nfyc.cn http://www.morning.lfdzr.cn.gov.cn.lfdzr.cn http://www.morning.kpypy.cn.gov.cn.kpypy.cn http://www.morning.stbfy.cn.gov.cn.stbfy.cn http://www.morning.nzwp.cn.gov.cn.nzwp.cn http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn http://www.morning.fkrzx.cn.gov.cn.fkrzx.cn http://www.morning.gyqnp.cn.gov.cn.gyqnp.cn http://www.morning.pshpx.cn.gov.cn.pshpx.cn http://www.morning.zcsyz.cn.gov.cn.zcsyz.cn http://www.morning.pmhln.cn.gov.cn.pmhln.cn http://www.morning.mrbzq.cn.gov.cn.mrbzq.cn http://www.morning.gbpanel.com.gov.cn.gbpanel.com http://www.morning.mqwnp.cn.gov.cn.mqwnp.cn http://www.morning.mczjq.cn.gov.cn.mczjq.cn http://www.morning.htmhl.cn.gov.cn.htmhl.cn http://www.morning.xxgfl.cn.gov.cn.xxgfl.cn