码迷,mamicode.com
首页 > 其他好文 > 详细

小白月赛-9

时间:2018-11-17 23:51:11      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:gif   问题   namespace   include   代码   none   size   效果   col   

本场新生赛和今晚的小白月赛
本次比赛还是暴力了自己很大的问题,代码量和思维量都明显不够,只会暴力和找规律,遇到稍微思维量大一点的
代码题就没办法。
优点是,比赛完后立马补题,效果最好。

A-签到  

技术分享图片
 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<string.h>
 4 #include<algorithm>
 5 #define ll long long
 6 using namespace std;
 7 const ll mod = 1e9+7;
 8 const int maxx = 1e5+7;
 9 struct node
10 {
11     ll x,y;
12 }p[maxx];
13 ll qpow(ll a,ll b)
14 {
15     ll ans=1;
16     while(b)
17     {
18         if(b&1)
19         {
20             ans=ans*a%mod;
21         }
22         a=a*a%mod;
23         b/=2;
24     }
25     return ans;
26 }
27 int main()
28 {
29     ll n;
30     while(~scanf("%lld",&n))
31     {
32         for (int i=1; i<=n; i++)
33         {
34             scanf("%lld%lld",&p[i].x,&p[i].y);
35         }
36         ll ans=1;
37         ll a=1;
38         ll b=1;
39         for(int i=1; i<=n; i++)
40         {
41            a=a*(p[i].y-p[i].x)%mod;
42            b=b*qpow(p[i].y,mod-2)%mod;
43         }
44         ans=(1-a*b%mod+mod)%mod;
45         printf("%lld\n",ans);
46     }
47     return 0;
48 }
View Code


本题最开始我想错了,正解是每层楼掉东西的概率p[i]=a[i]/b[i],那么不掉东西的概率应该是
                   p=sigma((b[i]-a[i])/b[i])

那么掉东西的概率就是1-p,那么·这个题再求逆元,就很好办了。

 

B-法法  

技术分享图片
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
int main(){
  int t;
  scanf("%d",&t);
  long long n;
  while(t--){
    scanf("%lld",&n);
    if (n==1 || n==2)printf("1\n");
    else printf("0\n");
  }
 
  return 0;
}
View Code

水题:特判1,2即可


E-换个角度思考

技术分享图片
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxx  = 1e5+7;
int n,m,ans[maxx];
struct node
{
    int val;
    int id;
} s[maxx];
bool cmpnode(node x,node y)
{
    return x.val<y.val;
}
struct Query
{
    int l,r;
    int h;
    int id;
} q[maxx];
bool cmpQuery(Query x,Query y)
{
    return x.h < y.h;
}
int tree[maxx];
int lowbit(int x)
{
    return x&(-x);
}
void add(int i,int x)
{
    while(i<maxx)
    {
        tree[i]+=x;
        i+=lowbit(i);
    }
}
int sum(int i)
{
    int sum=0;
    while(i>0)
    {
        sum+=tree[i];
        i-=lowbit(i);
    }
    return sum;
}
int query(int l,int r)
{
    return sum(r)-sum(l-1);
}
int main()
{
    memset(tree,0,sizeof(tree));
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&s[i].val);
        s[i].id=i;
    }
    sort(s+1,s+1+n,cmpnode);//按值进行排序
    for (int i=1;i<=m;i++){
        scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].h);
        q[i].id=i;
    }
    sort(q+1,q+1+m,cmpQuery);//按照询问的右区间进行排序
    int top=1;//对于每个值,如果这个数在某个区间
    for (int i=1;i<=m;i++){
        while(top<=n && s[top].val<=q[i].h)//这个值小于x
        {
            add(s[top].id,1);
            top++;
        }
        ans[q[i].id]=query(q[i].l,q[i].r);
    }
    for (int i=1;i<=m;i++){
      printf("%d\n",ans[i]);
    }
    return 0;
}
View Code


这个题目数据有问题,暴力能过。。。。
正解是莫队,对询问和值进行排序,然后树状数组维护。


H-论如何出一道水题

技术分享图片
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main(){
  long long n;
  while(~scanf("%lld",&n)){
    if(n==1)printf("2\n");
  else
    printf("%lld\n",2*n-1);
  }
  return 0;
}
View Code


水题,MAX(i,j),且i,j互质。
那么问题很简单,i=n-1,j=n,即可。但是要特判1;

小白月赛-9

标签:gif   问题   namespace   include   代码   none   size   效果   col   

原文地址:https://www.cnblogs.com/bluefly-hrbust/p/9976316.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!