GYM1014092010-2011 ACM-ICPC, NEERC, Western Subregional Contest
Posted yljiang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GYM1014092010-2011 ACM-ICPC, NEERC, Western Subregional Contest相关的知识,希望对你有一定的参考价值。
A-Area and Circumference
题目大意:在平面上给出$N$个三角形,问周长和面积比的最大值。
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <stdio.h> 5 #include <cstdio> 6 #include <cmath> 7 #include <string> 8 #include <queue> 9 #include <vector> 10 #include <map> 11 #include <iomanip> 12 using namespace std; 13 const int N=1e5+7; 14 //const double eps = 1e-8; 15 double ax,ay,bx,by; 16 double x[N]; 17 double chang,kuan; 18 int main() 19 { 20 freopen("area.in","r",stdin); 21 freopen("area.out","w",stdout); 22 int n; 23 scanf("%d",&n); 24 for(int i=1;i<=n;i++) 25 { 26 scanf("%lf%lf%lf%lf",&ax,&ay,&bx,&by); 27 chang=fabs(bx-ax); 28 kuan=fabs(ay-by); 29 x[i]=chang*kuan/(chang+chang+kuan+kuan); 30 } 31 sort(x+1,x+1+n); 32 printf("%lf ",x[n]); 33 }
B-Brothers
题目大意:找出区间$[M,N]$上的质数数对$(X,Y)$的个数,满足$Y=X+2010$。
题解:预处理出$ans[i]$表示$[1,i imes 10^6]$的答案,对于区间$[1,N]$的答案,找出最大的$i imes 10^6 leq N$后,剩余部分用Miller Rabin素数测试暴力判断即可。
1 #include <iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 using namespace std; 6 typedef long long ll; 7 const int maxn=1002018; 8 const int tim=10; 9 int ans[1001]={0,22162,39960,56504,72029,87374,102087,116684,130917,145138,158900,172579,186186,199504,212815,226012,239060,252055,265039,277582,290306,302753,315347,327740,340204,352676,364976,377351,389542,401678,413873,425813,437786,449650,461664,473469,485253,496964,508752,520716,532454,544071,555650,567286,578800,590252,601935,613437,624868,636252,647803,659189,670497,681769,693156,704437,715744,727017,738229,749350,760546,771730,782682,793812,804977,816012,827017,838009,849177,860242,871091,882070,893091,904040,914879,925688,936546,947316,958035,968682,979491,990300,1001120,1011903,1022710,1033384,1044113,1054709,1065465,1076165,1086714,1097488,1108033,1118588,1129114,1139793,1150463,1160993,1171549,1181916,1192500,1203080,1213641,1224155,1234623,1245030,1255333,1265779,1276099,1286610,1297066,1307446,1317880,1328309,1338642,1349020,1359589,1369966,1380172,1390545,1400835,1411036,1421318,1431682,1442042,1452476,1462651,1473039,1483330,1493528,1503615,1513892,1524071,1534257,1544467,1554658,1564809,1575125,1585323,1595475,1605558,1615665,1625844,1636197,1646359,1656355,1666586,1676738,1686778,1696826,1707045,1717021,1727143,1737160,1747336,1757356,1767491,1777374,1787433,1797302,1807335,1817289,1827164,1837253,1847266,1857121,1867157,1877135,1887195,1897159,1907125,1917103,1927057,1936960,1946916,1956913,1966886,1976800,1986804,1996638,2006618,2016407,2026303,2036063,2045939,2055825,2065720,2075594,2085471,2095221,2105137,2115012,2124818,2134736,2144682,2154439,2164312,2174072,2183807,2193483,2203170,2212957,2222626,2232371,2242204,2252075,2261826,2271603,2281461,2291119,2300773,2310701,2320364,2330115,2339802,2349679,2359372,2369003,2378687,2388379,2398041,2407660,2417273,2426970,2436604,2446282,2455887,2465588,2475048,2484882,2494468,2504153,2513829,2523385,2532890,2542505,2552109,2561830,2571464,2581077,2590548,2600347,2609771,2619239,2628826,2638545,2648134,2657578,2667127,2676740,2686362,2695939,2705449,2715008,2724558,2734147,2743655,2753145,2762639,2772242,2781776,2791279,2800819,2810428,2819848,2829424,2838997,2848498,2857890,2867319,2876825,2886167,2895670,2905174,2914772,2924198,2933616,2943023,2952444,2961936,2971360,2980820,2990282,2999761,3009153,3018577,3028072,3037477,3047098,3056604,3066018,3075386,3084805,3094230,3103795,3113305,3122725,3132196,3141546,3150675,3159961,3169335,3178755,3188112,3197466,3206908,3216209,3225409,3234653,3243898,3253225,3262556,3271921,3281305,3290568,3299860,3309211,3318547,3327838,3337015,3346374,3355835,3365017,3374413,3383749,3392993,3402286,3411599,3420914,3430196,3439419,3448686,3457954,3467150,3476475,3485765,3495061,3504383,3513599,3522893,3532166,3541613,3550838,3560052,3569298,3578561,3587776,3596959,3606211,3615388,3624716,3633917,3642999,3652160,3661372,3670677,3679911,3689117,3698205,3707478,3716663,3725719,3734908,3744080,3753298,3762526,3771658,3780817,3789991,3799186,3808387,3817455,3826727,3835857,3845014,3854154,3863325,3872473,3881743,3891068,3900261,3909449,3918682,3927880,3936968,3946158,3955298,3964525,3973697,3982755,3991869,4000954,4010096,4019212,4028348,4037537,4046611,4055706,4064838,4073785,4083031,4092093,4101073,4110291,4119333,4128352,4137386,4146588,4155675,4164818,4173750,4182963,4192195,4201355,4210493,4219666,4228801,4237955,4246939,4256014,4265021,4274065,4283120,4292070,4301189,4310144,4319193,4328341,4337311,4346257,4355294,4364233,4373314,4382351,4391311,4400380,4409437,4418508,4427571,4436679,4445650,4454777,4463778,4473046,4481994,4491008,4499962,4508913,4517990,4527118,4536042,4544992,4553934,4562906,4571949,4580811,4589824,4598892,4607771,4616908,4625875,4634890,4643749,4652685,4661675,4670490,4679458,4688493,4697549,4706466,4715373,4724374,4733206,4742080,4751076,4759994,4768974,4777923,4787049,4796042,4805052,4813919,4822847,4831758,4840689,4849787,4858730,4867657,4876556,4885559,4894463,4903528,4912391,4921244,4930210,4939070,4948085,4957088,4965958,4974842,4983885,4992778,5001734,5010631,5019484,5028229,5037187,5046056,5054869,5063733,5072821,5081760,5090676,5099487,5108402,5117176,5126133,5135023,5144001,5153031,5161914,5170777,5179585,5188479,5197424,5206413,5215381,5224205,5233146,5241973,5250788,5259507,5268202,5277141,5286122,5294992,5303867,5312787,5321771,5330580,5339385,5348130,5356893,5365678,5374505,5383314,5392171,5400966,5409975,5418705,5427532,5436462,5445272,5454048,5462870,5471565,5480423,5489054,5497913,5506752,5515486,5524253,5533028,5541873,5550708,5559464,5568124,5576814,5585602,5594426,5603158,5612006,5620779,5629603,5638422,5647235,5655967,5664856,5673626,5682263,5691059,5699866,5708613,5717531,5726343,5735051,5743896,5752655,5761428,5770127,5778858,5787548,5796421,5805127,5813901,5822664,5831427,5840117,5848724,5857357,5866030,5874775,5883623,5892418,5901270,5910010,5918606,5927365,5936086,5944661,5953312,5962080,5970887,5979690,5988527,5997282,6006082,6014759,6023310,6031979,6040618,6049307,6057997,6066507,6075274,6084001,6092699,6101560,6110273,6118900,6127793,6136599,6145283,6153828,6162472,6171137,6179815,6188493,6197230,6205971,6214478,6223368,6232056,6240681,6249295,6257911,6266687,6275339,6284032,6292838,6301493,6310249,6318874,6327549,6336277,6344911,6353656,6362408,6371082,6379850,6388652,6397391,6406134,6414911,6423626,6432135,6440712,6449377,6457917,6466520,6475109,6483752,6492386,6501083,6509766,6518436,6527073,6535615,6544268,6552932,6561660,6570313,6579069,6587680,6596388,6604989,6613749,6622392,6631010,6639822,6648447,6657206,6665876,6674542,6683141,6691812,6700431,6709033,6717617,6726223,6734905,6743570,6752159,6760767,6769434,6777962,6786571,6795291,6803834,6812541,6821242,6829842,6838352,6846962,6855541,6864186,6872766,6881464,6890099,6898648,6907213,6915709,6924206,6932744,6941293,6950020,6958428,6966962,6975611,6984208,6992681,7001368,7009935,7018585,7027059,7035516,7044189,7052797,7061520,7070149,7078785,7087385,7095964,7104551,7113057,7121739,7130235,7138715,7147371,7155927,7164466,7173048,7181643,7190234,7198790,7207483,7216068,7224567,7233232,7241770,7250304,7258801,7267439,7276066,7284483,7292987,7301385,7309891,7318606,7327182,7335747,7344337,7352851,7361435,7369856,7378363,7386862,7395405,7403989,7412558,7421165,7429843,7438432,7446932,7455400,7463877,7472378,7480918,7489367,7497868,7506522,7514936,7523349,7531828,7540467,7548895,7557585,7566070,7574648,7583224,7591605,7600094,7608609,7617022,7625395,7633916,7642369,7650926,7659462,7667971,7676518,7684968,7693352,7701872,7710283,7718784,7727332,7735802,7744364,7752999,7761555,7770097,7778487,7786946,7795366,7803781,7812209,7820475,7828800,7837242,7845597,7854189,7862576,7871159,7879751,7888194,7896597,7905167,7913665,7922034,7930527,7938887,7947366,7955919,7964396,7972782,7981204,7989566,7998031,8006609,8015037,8023348,8031848,8040374,8048921,8057431,8065945,8074451,8082842,8091296,8099666,8108062,8116448,8124947,8133370,8141716,8150284,8158659,8167112,8175601,8183993,8192383,8200813,8209319,8217804,8226343,8234733,8243061,8251484,8260009,8268522,8276815,8285305,8293706,8302133,8310647,8319064,8327383,8335886,8344248,8352581,8361080,8369308,8377777,8386219,8394583,8403035,8411410,8419726,8428043,8436495,8444953,8453324,8461605,8470081,8478261,8486805,8495218,8503784,8512008,8520583,8529032,8537484,8545875,8554233,8562701,8571216,8579616,8588048,8596440,8604879,8613246,8621643,8630038,8638345,8646663,8654946,8663327,8671682,8679956,8688183,8696578,8705069,8713411,8721806,8730256,8738746,8747131,8755498,8763889,8772268,8780736,8789131,8797579,8806001,8814246,8822629,8830990,8839467,8847870,8856218,8864510,8872889,8881197,8889643,8897977,8906302,8914654,8922984,8931358,8939789,8948217,8956510,8964915,8973271,8981549,8989835,8998252,9006569,9014875,9023203,9031693,9039995,9048378,9056769,9065113,9073351,9081715,9090110,9098352,9106770,9115150,9123548,9131896,9140360,9148706,9156932,9165272,9173633,9181825,9190202,9198649,9207006,9215367,9223619,9231867,9240097,9248485,9256917,9265398,9273629}; 10 bool ispl[maxn],ispr[maxn]; 11 ll pow(ll a,ll b,ll mod){ 12 int ans=1; 13 while(b){ 14 if(b&1) ans=(ans*a)%mod; 15 a=(a*a)%mod; 16 b>>=1; 17 } 18 return ans; 19 } 20 bool isp(ll n){ 21 int i,j,t; 22 ll a,x,y,u; 23 if(n==2)return true; 24 if(n<2||!(n&1)) return false; 25 t=0,u=n-1; 26 while((u&1)==0)t++,u>>=1; 27 for(i=1;i<=tim;i++){ 28 a=rand()%(n-1)+1; 29 x=pow(a,u,n); 30 for(j=0;j<t;j++){ 31 y=(x*x)%n; 32 if(y==1&&x!=1&&x!=n-1)return false; 33 x=y; 34 } 35 if(x!=1)return false; 36 } 37 return true; 38 } 39 int main() 40 { 41 freopen("brothers.in","r",stdin); 42 freopen("brothers.out","w",stdout); 43 int l,r; 44 while(~scanf("%d%d",&l,&r)){ 45 if(l+2010>r){ 46 printf("0 "); 47 continue; 48 } 49 int resl=0; 50 int resr=0; 51 int tmpl=l/(int)1e6; 52 int tmpr=r/(int)1e6; 53 memset(ispl,0,sizeof(ispl)); 54 memset(ispr,0,sizeof(ispr)); 55 int tl=max(tmpl*(int)1e6-2010+1,1); 56 int tr=max(tmpr*(int)1e6-2010+1,1); 57 for(int i=tl;i<l+2010;i++){ 58 ispl[i-tl]=isp((ll)i); 59 } 60 for(int i=tl;i<l;i++){ 61 if(ispl[i-tl]&&ispl[i-tl+2010]) 62 resl++; 63 } 64 resl+=ans[tmpl]; 65 for(int i=tr;i<=r;i++){ 66 ispr[i-tr]=isp((ll)i); 67 } 68 for(int i=tr;i<=r-2010;i++){ 69 if(ispr[i-tr]&&ispr[i-tr+2010]) 70 resr++; 71 } 72 resr+=ans[tmpr]; 73 74 printf("%d ",resr-resl); 75 } 76 }
D-Domino
题目大意:
题解:
1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #include <stdio.h> 5 #include <cstdio> 6 #include <cmath> 7 #include <string> 8 #include <queue> 9 #include <vector> 10 #include <map> 11 #include <iomanip> 12 using namespace std; 13 const int N=1e4+7; 14 int a[N],b[N]; 15 int main() 16 { 17 freopen("domino.in","r",stdin); 18 freopen("domino.out","w",stdout); 19 int n,r,sum=0,ans=0; 20 int x,y; 21 scanf("%d%d",&n,&r); 22 for(int i=1;i<=n;i++){ 23 scanf("%d%d",&a[i],&b[i]); 24 sum+=a[i]+b[i]; 25 } 26 int rr; 27 for(int i=1;i<=2*r;i++){ 28 scanf("%d",&rr); 29 if(i==1)x=rr; 30 if(i==2*r)y=rr; 31 } 32 if(n==1){ 33 if(a[1]==x||a[1]==y||b[1]==x||b[1]==y){ 34 printf("%d",-1); 35 return 0; 36 } 37 } 38 if(n==2){ 39 if(a[1]==b[1]&&a[2]==b[2]) 40 if((a[1]==x&&a[2]==y)||(a[1]==y&&a[2]==x)){ 41 printf("%d",-1); 42 return 0; 43 } 44 } 45 int flag1=0,flag2=0; 46 for(int i=1;i<=n;i++) 47 { 48 if(a[i]==b[i]){ 49 if(flag1==0&&a[i]==x) 50 flag1=1; 51 else if(flag2==0&&a[i]==y) 52 flag2=1; 53 } 54 if(a[i]==x||a[i]==y||b[i]==x||b[i]==y) 55 ans=max(a[i]+b[i],ans); 56 } 57 if(flag1&&flag2) 58 ans=max(x+x+y+y,ans); 59 printf("%d",sum-ans); 60 }
E-Express Lines
题目大意:在一个有 N个点的环上选择不少于2个点,而且选择的点不相邻,求方案数。
题解:拆换成链,f[i][0/1][0/1]表示前i个点是否选择第1个点,是否选择第i个点的方案数。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cmath> 5 #include<cstring> 6 #include<algorithm> 7 using namespace std; 8 int n; 9 long long mod; 10 long long f[1000005][2][2]; 11 int main() 12 { 13 int i; 14 freopen("express.in","r",stdin); 15 freopen("express.out","w",stdout); 16 scanf("%d%lld",&n,&mod); 17 f[3][0][0]=(long long)2; 18 f[3][1][0]=(long long)1; 19 f[3][1][1]=(long long)1; 20 f[3][0][1]=(long long)1; 21 for(i=4;i<=n;i++) 22 { 23 f[i][0][0]=(f[i-1][0][0]+f[i-1][0][1])%mod; 24 f[i][0][1]=f[i-1][0][0]%mod; 25 26 f[i][1][0]=(f[i-1][1][1]+f[i-1][1][0])%mod; 27 f[i][1][1]=f[i-1][1][0]; 28 } 29 if(n<=3) printf("0"); 30 else printf("%lld",(f[n][1][0]+f[n][0][0]+f[n][0][1]-(long long)n-(long long)1+mod*(n/mod+1))%mod); 31 return 0; 32 }
G-Game
题目大意:有m个球,每个球上有两个按钮,一个对应蓝色,一个对应红色,但不知道哪个按钮对应哪种颜色。现在以放回的方式依次取出两个球,记录按下的按钮对应的颜色,如果两个球选择的颜色相同,则赢,否则输。现在知道其中一个取出的球的编号不超过$k$,且这个球选择的颜色是蓝色,问赢的概率。
题解:设事件$A$为赢,$B$为其中一个取出的球的编号不超过$k$且这个球选择的颜色是蓝色。
$P(A|B)=frac{P(AB)}{P(B)}=frac{2(k)(m)-k^2}{2(k)(2m)-k^2}=frac{2m-k}{4m-k}$
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cmath> 5 #include<cstring> 6 #include<algorithm> 7 using namespace std; 8 9 int n; 10 double k,m,a,b; 11 12 int main() 13 { 14 int i; 15 freopen("game.in","r",stdin); 16 freopen("game.out","w",stdout); 17 scanf("%d",&n); 18 for(i=1;i<=n;i++) 19 { 20 scanf("%lf%lf",&k,&m); 21 a=1.0*(2.0*m-k);b=(4.0*m-k); 22 printf("%.11lf ",a/b); 23 } 24 return 0; 25 }
F-"Injurious" Triples
题目大意:在一个序列里面找出一个三个数的子序列满足这三个数按原顺序构成等差数列。
题解:暴力枚举两个数,判断另一个数是否存在。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cmath> 5 #include<cstring> 6 #include<algorithm> 7 using namespace std; 8 9 int n,lim; 10 int a[100005],f[2000005]; 11 void solve() 12 { 13 int i,j; 14 for(i=1;i<=n;i++) 15 for(j=i+1;j<=n;j++) 16 if(2*a[j]-a[i]>=0&&2*a[j]-a[i]<=lim&&f[2*a[j]-a[i]]>j) 17 { 18 puts("Yes"); 19 printf("%d %d %d",i,j,f[2*a[j]-a[i]]); 20 return; 21 } 22 23 puts("No"); 24 } 25 int main() 26 { 27 int i,j; 28 freopen("injurious.in","r",stdin); 29 freopen("injurious.out","w",stdout); 30 scanf("%d",&n); 31 for(i=1;i<=n;i++) 32 scanf("%d",&a[i]); 33 lim=a[1]; 34 for(i=2;i<=n;i++) 35 if(a[i]>lim) lim=a[i]; 36 for(i=1;i<=n;i++) 37 f[a[i]]=i; 38 solve(); 39 return 0; 40 }
以上是关于GYM1014092010-2011 ACM-ICPC, NEERC, Western Subregional Contest的主要内容,如果未能解决你的问题,请参考以下文章
OpenAI Gym 入门与提高 Gym环境构建与最简单的RL agent
强化学习 平台 openAI 的 gym 安装 (Ubuntu环境下如何安装Python的gym模块)
2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys