这次还是能看的0 0,没出现一题掉分情况。

QAQ前两次掉分还被hack了0 0,两行清泪。

A. Find Extra One

 

You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.

Input

The first line contains a single positive integer n (2 ≤ n ≤ 105).

The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109,xi ≠ 0). No two points coincide.

Output

Print "Yes" if there is such a point, "No" — otherwise.

You can print every letter in any case (upper or lower).

Examples
input
3
1 1
-1 -1
2 -1
output
Yes
input
4
1 1
2 2
-1 1
-2 2
output
No
input
3
1 2
2 1
4 60
output
Yes

题意:给你n个平面上的点,能否去掉一个使得所有点在y轴一侧。给出的点不会在y轴上。

题解:水题,统计下x>0 和 x<0的数字个数就好了。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
int n,left,right,x,y;
left=right=;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(x>)
right++;
else
left++;
}
if(right<= || left<=)
printf("Yes\n");
else
printf("No\n");
return ;
}

B. Position in Fraction

 

You have a fraction . You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point.

Input

The first contains three single positive integers abc (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).

Output

Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1.

Examples
input
1 2 0
output
2
input
2 3 7
output
-1

题意:给出一个分数$ \frac{a}{b} $ ,看c在该分数小数点后几位。

题解:$ \frac{a}{b} $化为最简$ \frac{a'}{b'} $后,我们模拟除法列竖式求答案的过程。由于列竖式的过程中余下的数总比b'小,所以最多b'个不同余数,列竖式的过程中一旦出现相同的余数则是进入了循环。所以我们最多做b'次除法就能求出c是否存在于该分数小数点后以及c的位置。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int gcd(int a,int b)
{
int c;
while(b)
{
c=a%b;
a=b;
b=c;
}
return a;
}
int main()
{
int a,b,c,d,e,i;
scanf("%d%d%d",&a,&b,&c);
d=gcd(a,b);
a/=d;
b/=d;
d=a/b;
a-=d*b;
a*=;
for(i=;i<=;i++)
{
d=a/b;
a-=d*b;
if(d==c)
break;
a*=;
}
if(i>)
printf("-1\n");
else
printf("%d\n",i);
return ;
}

C. Remove Extra One

 

You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible.

We remind that in a sequence of numbers a1, a2, ..., ak the element ai is a record if for every integer j (1 ≤ j < i) the following holds:aj < ai.

Input

The first line contains the only integer n (1 ≤ n ≤ 105) — the length of the permutation.

The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the permutation. All the integers are distinct.

Output

Print the only integer — the element that should be removed to make the number of records the maximum possible. If there are multiple such elements, print the smallest one.

Examples
input
1
1
output
1
input
5
5 1 2 3 4
output
5
Note

In the first example the only element can be removed.


题意:给出1~n的一个排列,要求你找出一个数,在排列中去掉它以后符合条件的数最多,如果有多个则选最小的那个。若ai符合条件,对于任意1≤j<i,aj<ai

题解:那么我们写个bit来记录数列前面小于ai的个数,set来求取大于ai的第一个数。如果ai前面有i-2个数小于ai,那么用set的lonwer_bound找到大于ai的第一个数p,并且该数p对于答案的贡献num[p]++。注意如果ai前面有i-1个数小于ai,那么ai对于答案的贡献num[ai]--。然后从小到大找贡献最大的那个。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+;
int bits[N];
int num[N];
int n,m,T,k,p;
set<int> pt;
set<int>::iterator it;
void add(int i,int x)
{
while(i<=n)
{
bits[i]+=x;
i+=(i &(-i));
}
return ;
}
int sum(int i)
{
int res=;
while(i>)
{
res+=bits[i];
i-=(i &(-i));
}
return res;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&p);
if((p-> && sum(p-)==i-) || (p-== && i==))
{
it=pt.lower_bound(p);
num[*it]++;
}
if((p-> && sum(p-)==i-) || (p-== && i==))
num[p]--;
pt.insert(p);
add(p,);
}
int maxn=num[];
k=;
for(int i=;i<=n;i++)
{
if(maxn<num[i])
{
maxn=num[i];
k=i;
}
}
printf("%d\n",k);
return ;
}

D. Unusual Sequences

 

Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such that gcd(a1, a2, ..., an) = x and . As this number could be large, print the answer modulo 109 + 7.

gcd here means the greatest common divisor.

Input

The only line contains two positive integers x and y (1 ≤ x, y ≤ 109).

Output

Print the number of such sequences modulo 109 + 7.

Examples
input
3 9
output
3
input
5 8
output

0


题意:让你找出符合条件的序列数,并mod 1e9+7。序列需满足gcd(a1~n)=x,sum(a1~n)=y。

题解:首先把一个数p分解成几个数成组成的序列有$ 2^{p-1} $,用组合的隔板法轻易可证。x能整除y说明存在这样的序列,反之不存在。然后d=y/x,将d分解成质数乘积,算算不同质数的个数以及具体是哪些质数,容斥一下就能求出答案了。

 #include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+;
int prime[N],inf[N],pcnt;
void primer(int n)
{
pcnt=;
for(int i=;i<=n;i++)
{
if(!inf[i])
{
prime[++pcnt]=i;
}
for(int j=;j<=pcnt;j++)
{
if(prime[j]>n/i) break;
inf[prime[j]*i]=;
if(i%prime[j]==) break;
}
}
return ;
}
LL quick_pow(LL x,LL n)
{
LL res=;
while(n)
{
if(n&)
res=(res*x)%mod;
n>>=;
x=(x*x)%mod;
}
return res;
}
LL x,y,d,n,k;
int all;
LL num[];
int cnt;
LL ans,p;
int main()
{
primer();
scanf("%lld%lld",&x,&y);
if(y%x!=)
{
printf("0\n");
return ;
}
y/=x;
d=y;
cnt=;
for(int i=;(LL)prime[i]*prime[i]<=d;i++)
{
n=(LL)prime[i];
if(d%n==)
{
num[++cnt]=n;
while(d%n==) d/=n;
}
}
if(d!=) num[++cnt]=d;
ans=;
all=(<<cnt)-;
for(int i=,j,k,ok;i<=all;i++)
{
j=i;
k=;
p=;
ok=;
while(j)
{
k++;
if(j&) p*=num[k],ok=-ok;
j>>=;
}
ans=(ans+quick_pow(,y/p-)*ok)%mod;
}
printf("%lld\n",(ans%mod+mod)%mod);
return ;
}

Codeforces Round #450 (Div. 2) ABCD的更多相关文章

  1. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  2. Codeforces Round #450 (Div. 2)

    Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  5. Codeforces Round #449 (Div. 2)ABCD

    又掉分了0 0. A. Scarborough Fair time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  7. Codeforces Round #248 (Div. 2) (ABCD解决问题的方法)

    比赛链接:http://codeforces.com/contest/433 A. Kitahara Haruki's Gift time limit per test:1 second memory ...

  8. Codeforces Round #427 (Div. 2)——ABCD

    http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...

  9. Codeforces Round #412 (Div. 2)ABCD

    tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...

随机推荐

  1. 【CodeForces】835D Palindromic characteristics

    [题意]给你一个串,让你求出k阶回文子串有多少个.k从1到n.k阶子串的定义是:子串本身是回文串,而且它的左半部分也是回文串. [算法]区间DP [题解]涉及回文问题的区间DP都可以用类似的写法,就是 ...

  2. 小程序var that=this

    小程序的js函数中,一般第一句就是var that=this,那么此语句的必要性是什么呢?下面用一段代码来解释这个问题 Page({ //页面的初始数据 loadUsers: function () ...

  3. JqGrid自定义(图片)列

    $("#gridTable").jqGrid({ //...其它属性 colModel: [ //...其它列 { name: , align: "center" ...

  4. postman测试express restful接口

    安装express及postman var express = require('express') var app = express(); var calculation = require('. ...

  5. 【swupdate文档 一】嵌入式系统的软件管理

    嵌入式系统的软件管理 嵌入式系统变得越来越复杂, 它们的软件也反映了这种复杂性的增加. 为了支持新的特性和修复,很有必要让嵌入式系统上的软件 能够以绝对可靠的方式更新. 在基于linux的系统上,我们 ...

  6. Ubuntu 14.04 安装gstreamer0.10-ffmpeg

    sudo apt-add-repository ppa:mc3man/trusty-media sudo apt-get update sudo apt-get install -y gstreame ...

  7. 通过call_usermodehelper()在内核态执行用户程序【转】

    转自:http://edsionte.com/techblog/archives/category/linux%E5%86%85%E6%A0%B8%E7%BC%96%E7%A8%8B 背景 如何在Li ...

  8. 设计模式之笔记--建造者模式(Builder)

    建造者模式(Builder) 定义 建造者模式(Builder),将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 类图 描述 Builder:定义一个建造者抽象类,以规范产 ...

  9. 坐标转换——GCJ-02

    WGS84(World Geodetic System 1984),是为GPS 全球定位系统 使用而建立的坐标系统GCJ-02,我国在WGS84的基础上加密得到BD-09,百度坐标在GCJ-02基础上 ...

  10. 手机meta标签(保存下来省的每次都找)

    手机网站Meta标签 手机端特有的Meta标签 1.<meta name="viewport" id="viewport" content="w ...