P76
竞赛时间: ????年??月??日??:??-??:??

题目名称
名称 he she it
输入 he.in she.in it.in
输出 he.out she.out it.out
每个测试点时限 1 秒 1 秒 1 秒
内存限制 512MB 512MB 512MB
测试点数目 10 10 10
每个测试点分值 10 10 10
是否有部分分
题目类型 传统 传统 传统

 


【问题描述】
一张长度为N的纸带, 我们可以从左至右编号为0 − N( 纸带最左端标号为
0)。 现在有M次操作, 每次将纸带沿着某个位置进行折叠, 问所有操作之后纸带
的长度是多少。
【输入格式】
第一行两个数字N, M如题意所述。
接下来一行M个整数代表每次折叠的位置。
【输出格式】
一行一个整数代表答案。
【样例输入】
5 2
3 5
【样例输出】
2
【样例解释】
树上有只鸟。
【数据规模与约定】
对于60%的数据, N, M ≤ 3000。
对于100%的数据, N ≤ 10^18, M ≤ 3000。

暴力60

  1. /*暴力60 似乎离散化一下好的多...考试的时候没时间了23333*/
  2. #include<cstdio>
  3. #define maxn 3010
  4. using namespace std;
  5. int n,m,a[maxn],x,P[maxn],c[maxn][maxn],f[maxn][maxn];
  6. int init(){
  7. int x=,f=;char s=getchar();
  8. while(s<''||s>''){if(s=='-')f=-;s=getchar();}
  9. while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
  10. return x*f;
  11. }
  12. int max(int x,int y){
  13. return x>y?x:y;
  14. }
  15. int main()
  16. {
  17. freopen("he.in","r",stdin);
  18. freopen("he.out","w",stdout);
  19. n=init();m=init();
  20. for(int i=;i<=n;i++)
  21. c[i][++c[i][]]=i,P[i]=i;
  22. int p,s1,s2,len=n;
  23. while(m--){
  24. x=init();p=P[x];
  25. s1=p;s2=len-p;
  26. if(s1<s2){
  27. for(int i=p+,k=p-;k>=;i++,k--)
  28. for(int j=;j<=c[k][];j++)
  29. c[i][++c[i][]]=c[k][j];
  30. for(int i=p,k=;i<=len;i++,k++){
  31. c[k][]=;
  32. for(int j=;j<=c[i][];j++){
  33. c[k][++c[k][]]=c[i][j];
  34. P[c[i][j]]=k;
  35. }
  36. }
  37. }
  38. else{
  39. for(int i=p+,k=p-;i<=len;i++,k--)
  40. for(int j=;j<=c[i][];j++){
  41. c[k][++c[k][]]=c[i][j];
  42. P[c[i][j]]=k;
  43. }
  44. }
  45. len=max(s1,s2);
  46. }
  47. printf("%d\n",len);
  48. return ;
  49. }

离线就100....

  1. /*离散化.... 考试的时候脑抽拿n直接做的*/
  2. #include<cstdio>
  3. #define ll long long
  4. #define maxn 3010
  5. #ifdef unix
  6. #define LL "%lld\n"
  7. #else
  8. #define LL "%I64d\n"
  9. #endif
  10. using namespace std;
  11. ll n,m,a[maxn],c[maxn];
  12. ll init(){
  13. ll x=,f=;char s=getchar();
  14. while(s<''||s>''){if(s=='-')f=-;s=getchar();}
  15. while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
  16. return x*f;
  17. }
  18. ll max(ll x,ll y){
  19. return x>y?x:y;
  20. }
  21. ll min(ll x,ll y){
  22. return x<y?x:y;
  23. }
  24. int main()
  25. {
  26. freopen("he.in","r",stdin);
  27. freopen("he.out","w",stdout);
  28. n=init();m=init();
  29. for(int i=;i<=m;i++)
  30. c[i]=init();
  31. for(int p=;p<=m;p++){
  32. ll P=c[p],mi=P*-n;//这个才是右端点 不是P*2-c[m]233s
  33. ll s1=P,s2=n-P;n=max(s1,s2);
  34. for(int i=;i<=m;i++)
  35. if(c[i]>P)c[i]=*P-c[i];
  36. if(mi<)for(int i=;i<=m;i++)
  37. c[i]-=mi;
  38. }
  39. printf(LL,n);
  40. return ;
  41. }


【问题描述】
给你M, S, L, R, 求满足L ≤ (S × x) mod M ≤ R最小的正整数x。

【输入格式】
第一行一个数T代表数据组数。
接下来T行每行四个数代表该组数据的M, S, L, R。
【输出格式】
对于每组数据, 输出一行代表答案。 如果不存在解, 输出“ −1”。
【样例输入】
1
5 4 2 3
【 样例输出】
2
【 样例解释】
叫南小鸟。
【数据规模与约定】
对于30%的数据, 保证有解且答案不超过10^6。
对于另外20%的数据, L = R。
对于100%的数据, 1 ≤ T ≤ 100,0 ≤ M, S, L,R ≤ 10^9。

暴力50

  1. /*这题无了语了 本来50来 想了想 嗯都用gcd搞吧 可能快点 然后就20了*/
  2. #include<iostream>
  3. #include<cstdio>
  4. #define maxn 1000000
  5. #define ll long long
  6. #define inf 1e9+10
  7. using namespace std;
  8. ll T,M,S,L,R,x,y,gcd,ans;
  9. ll init(){
  10. ll x=,f=;char s=getchar();
  11. while(s<''||s>''){if(s=='-')f=-;s=getchar();}
  12. while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
  13. return x*f;
  14. }
  15. ll min(ll x,ll y){
  16. return x<y?x:y;
  17. }
  18. void Cl(){
  19. ans=inf;x=;y=;gcd=;
  20. }
  21. void Gcd(ll a,ll b){
  22. if(b==){x=;y=;gcd=a;}
  23. else{
  24. Gcd(b,a%b);
  25. ll tmp=x;x=y;y=tmp-a/b*y;
  26. }
  27. }
  28. void Solve1(){
  29. if(S%M==){
  30. ans=-;return;
  31. }
  32. Gcd(S,M);int r=,falg=;
  33. for(int c=L;c<=R;c++){
  34. if(c%gcd)continue;
  35. ll tmp=x*c/gcd;r=M/gcd;
  36. tmp=(tmp%r+r)%r;falg=;
  37. if(tmp==)tmp+=r;
  38. ans=min(ans,tmp);
  39. }
  40. if(falg==)ans=-;
  41. }
  42. void Solve2(){
  43. if(S%M==){
  44. ans=-;return;
  45. }
  46. int falg=;
  47. for(x=;x<=;x++){
  48. ll r=(S*x)%M;
  49. if(r>=L&&r<=R){
  50. falg=;break;
  51. }
  52. }
  53. if(falg)ans=x;
  54. else ans=-;
  55. }
  56. int main()
  57. {
  58. freopen("she.in","r",stdin);
  59. freopen("she.out","w",stdout);
  60. T=init();
  61. while(T--){
  62. M=init();S=init();
  63. L=init();R=init();
  64. Cl();
  65. if(R==L)Solve1();
  66. else Solve2();
  67. cout<<ans<<endl;
  68. }
  69. return ;
  70. }

正解嘛 你猜


【问题描述】
N个人坐成一圈, 其中第K个人拿着一个球。 每次每个人会以一定的概率向
左边的人和右边的人传球。 当所有人都拿到过球之后, 最后一个拿到球的人即为
胜者。 求第N个人获胜的概率。( 所有人按照编号逆时针坐成一圈)
【输入格式】
第一行一个数T代表数据组数。
对于每组数据, 第一行两个整数N, K如题意所述。
接下来每行一个实数p代表该人将球传给右边的人的概率。
【输出格式】
对于每组数据, 一行一个实数代表答案, 保留9位小数。
【样例输入】
1
5 1
0.10
0.20
0.30
0.40
0.50
【 样例输出】
0.007692308
【 样例解释】
然后鸟是我的。
【数据规模与约定】
对于20%的数据, N ≤ 3。
对于70%的数据, T, N ≤ 100。
对于100%的数据, T ≤ 10000,1 ≤ N ≤ 100。

Orz...

  1. /*还有待研究2333*/
  2. #include<cstdio>
  3. #define maxn 110
  4. #define ld long double
  5. using namespace std;
  6. int T,n,k,a[maxn],b[maxn];
  7. ld p[maxn],q[maxn],P,Q,ans;
  8. void Cal(int m){
  9. /*int l=a[m],r=b[m];
  10. q[l]=(q[m]*q[l])/(1-q[m]*p[l]);
  11. p[l]=1-q[l];
  12. p[r]=(p[m]*p[r])/(1-p[m]*q[r]);
  13. q[r]=1-p[r];
  14. b[l]=r;a[r]=l;*/
  15. int l=a[m],r=b[m];
  16. long double pa=p[l],pb=p[m],pc=p[r];
  17. p[l]=pa*pb/(-pa*(-pb));q[l]=-p[l];
  18. q[r]=(-pc)*(-pb)/(-pb*(-pc));p[r]=-q[r];
  19. b[l]=r;a[r]=l;
  20. }
  21. int main()
  22. {
  23. freopen("it.in","r",stdin);
  24. freopen("it.out","w",stdout);
  25. scanf("%d",&T);
  26. while(T--){
  27. scanf("%d%d",&n,&k);
  28. for(int i=;i<=n;i++){
  29. scanf("%llf",&p[i]);
  30. q[i]=-p[i];
  31. a[i]=i-;b[i]=i+;
  32. }
  33. a[]=n;b[n]=;
  34. if(n==)ans=;
  35. else if(n==)k==?-q[]:-p[];
  36. else if(k==){
  37. for(int i=;i<n-;i++)Cal(i);ans=-q[];
  38. }
  39. else if(k==n-){
  40. for(int i=;i<n-;i++)Cal(i);ans=-p[n-];
  41. }
  42. else {
  43. for(int i=;i<k;i++)Cal(i);
  44. for(int i=k+;i<n;i++)Cal(i);
  45. ans=q[k]*p[]+q[n-]*p[k];
  46. }
  47. printf("%.9f\n",double(ans));
  48. }
  49. return ;
  50. }

10.30 afternoon的更多相关文章

  1. gnuWin32-mini-2016.10.30

    2016-10-28 04:48 1,017,856 awk.exe ver 4.1.4 2016-10-29 00:26 77,312 bc.exe ver 1.06 2016-10-30 01:4 ...

  2. 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox

    [源码下载] 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) AutoSug ...

  3. 2016.10.30 NOIP模拟赛 day2 PM 整理

    满分:300分 直接全部爆零,真的是很坑啊! 10.30的题目+数据:链接:http://pan.baidu.com/s/1jHXLace 密码:i784 T1: 题目中的难点就是每次折叠的点可能应经 ...

  4. 10.30 正睿停课训练 Day12

    目录 2018.10.30 正睿停课训练 Day12 A 强军战歌(DP 树状数组 容斥) B 当那一天来临(思路) C 假如战争今天爆发(贪心) 考试代码 B C 2018.10.30 正睿停课训练 ...

  5. 第18次Scrum会议(10/30)【欢迎来怼】

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/30 17:19~17:38,总计19min.地点:东北师 ...

  6. 2016.10.30 NOIP模拟赛 day2 AM 整理

    题目+数据:链接:http://pan.baidu.com/s/1gfBg4h1 密码:ho7o 总共得了:130分, 1:100分  2:30分(只会这30分的暴力) 3:0(毫无思路) 虽然不高, ...

  7. [软件工程基础]2017.10.30 第三次 Scrum 会议

    决议 游心与李煦通沟通生成报告脚本问题,并调试相应代码 李煦通部署服务器,并做一定安全检查 石奇川设计实验流程和题库前端页面 王嘉睿爵测试网站基本流程,提出关于用户体验方面的建议 刘子渊阅读代码,为机 ...

  8. sql 从未连续的Id中选择10~30条数据

    select * from(select *,row_number()over(order by ProductID) as num from Products) as t where t.num&g ...

  9. Fifth scrum meeting - 2015/10/30

    概述 从昨天开始,我们的开发工作终于进入了正轨,由于之前没有mooc服务器API接口,一些工作无法进行. 因为我们团队开始开发较晚,因此我们将开发阶段的截至时间定为了下周五,测试阶段则压缩为下周周六和 ...

随机推荐

  1. property测试代码:

    // // main.m // TestVar2 // // Created by lishujun on 14-9-4. // Copyright (c) 2014年 lishujun. All r ...

  2. spoj gss2 : Can you answer these queries II 离线&&线段树

    1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang ...

  3. UIWebView 自定义网页中的alert和confirm提示框风格

    .h #import <UIKit/UIKit.h> @interface UIWebView (JavaScriptAlert) -(void)webView:(UIWebView *) ...

  4. Java语言基础(一) 标识符

    Java标识符的问题: ①不可以以数字开头 int 123number = 0; //错误 ②可以使用任意的货币符号(¥和$等等)中文也可以  int $i = 0; //正确 int ¥i = 1; ...

  5. Silicon Labs电容式触摸感应按键技术原理及应用

    市场上的消费电子产品已经开始逐步采用触摸感应按键,以取代传统的机械式按键.针对此趋势,Silicon Labs公司推出了内置微控制器(MCU)功能的电容式触摸感应按键(Capacitive Touch ...

  6. Delphi的Owner与Parent可以不一致,而且Owner不是必须存在(一共7个问题) good

    问题1:Owner与Parent不一致:新建一个Form,上面放一个Button1,一个Panel1,然后在Panel1上再放一个Button2,测试结果:procedure TForm1.Butto ...

  7. 在前台运行Service

    一个前台的 service是被用户强烈关注的从而不会在内存低时被系统杀死.前台 service必须在状态栏上提供一个通知,这个通知被放在"正在进行"区域中,这表示这个通知不能被解除,除非服务停止了或者 ...

  8. Python 入门教程 10 ---- Student Becomes the Teacher

    第一节 1 练习 1 设置三个的字典分别为lloyd,alice,tyler 2 对每一个的字典的key都设置为"name","homework" , &quo ...

  9. rt: Unknown command 'PATH='

  10. C++中new和malloc

    1.malloc的工作原理: malloc使用一个数据结构(链表)来维护分配空间链表的构成:分配的空间/上一个空间的数据/下一个空间/空间大小等信息.    对malloc分配的空间不要越界访问,因为 ...