Codeforces Round #232 (Div. 2)

昨晚打的一场,由于FBJJ助攻一道C,第一次挤进第一版了有木有。,。而且还打进div1了。,。,。

A题:http://codeforces.com/problemset/problem/397/A

A. On Segment's Own Points
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.

The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has nstudents. Dean's office allows i-th student to use the segment (li, ri) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students!

Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (n - 1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1.

Input

The first line contains a positive integer n (1 ≤ n ≤ 100). The (i + 1)-th line contains integers li and ri (0 ≤ li < ri ≤ 100) — the endpoints of the corresponding segment for the i-th student.

Output

On a single line print a single number k, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments.

Sample test(s)
input
3
0 5
2 8
1 6
output
1
input
3
0 10
1 5
7 15
output
3
由于数据量很小,。所以想的是用一个数组a[101]来记录i是否已用,每次输入都把[li ,ri )之间的标记下,最后再遍历下就能找出答案。。,不过开始逗比了多打了等号,后了看了九野巨的才改了。,。,

代码如下:

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
#define INF 0x7fffffff
struct point{
    int x,y;
}a[105];
int b[101];
int main()
{
    int n,x=101,y=0;
    scanf("%d",&n);
    int m1,m2;
    scanf("%d%d",&m1,&m2);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
        for(int j=a[i].x;j<a[i].y;j++)
            b[j]=1;
    }
    int ans=0;
    for(int i=m1;i<m2;i++)
    {
        if(!b[i])
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}

后来看了下别人的代码,发现有用一个flag数组记录左右边界,左边界++,右边界--,然后用sum累加,可以发现sum==0时才没有在那些区间内,感觉略屌

#include<stdio.h>
#include<string.h>
int flag[105];
int main (){
	int n,m,a,b,s,e,sum,k;
	int i,j;
	while(scanf("%d",&n)!=EOF){
		memset(flag,0,sizeof(flag));
		scanf("%d%d",&s,&e);
		for(i=1;i<n;i++){
			scanf("%d%d",&a,&b);
			flag[a]++,flag[b]--;
		}
		sum=0;
		k=0;
		for(i=0;i<=100;i++){
			sum+=flag[i];
			if(i>=s&&i<e&&sum==0)
			k++;
		}
		printf("%d\n",k);
	}
}
B题: http://codeforces.com/problemset/problem/397/B

B. On Corruption and Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to wealthy parents that he was able to obtain the graduation certificate.

The situation is complicated by the fact that each high education institution has the determined amount of voluntary donations, paid by the new students for admission — ni berubleys. He cannot pay more than ni, because then the difference between the paid amount andni can be regarded as a bribe!

Each rector is wearing the distinctive uniform of his university. Therefore, the uniform's pockets cannot contain coins of denomination more than ri. The rector also does not carry coins of denomination less than li in his pocket — because if everyone pays him with so small coins, they gather a lot of weight and the pocket tears. Therefore, a donation can be paid only by coins of denomination xberubleys, where li ≤ x ≤ ri (Berland uses coins of any positive integer denomination). Alexey can use the coins of different denominations and he can use the coins of the same denomination any number of times. When Alexey was first confronted with such orders, he was puzzled because it turned out that not all universities can accept him! Alexey is very afraid of going into the army (even though he had long wanted to get the green uniform, but his dad says that the army bullies will beat his son and he cannot pay to ensure the boy's safety). So, Alexey wants to know for sure which universities he can enter so that he could quickly choose his alma mater.

Thanks to the parents, Alexey is not limited in money and we can assume that he has an unlimited number of coins of each type.

In other words, you are given t requests, each of them contains numbers ni, li, ri. For each query you need to answer, whether it is possible to gather the sum of exactly ni berubleys using only coins with an integer denomination from li to ri berubleys. You can use coins of different denominations. Coins of each denomination can be used any number of times.

Input

The first line contains the number of universities t, (1 ≤ t ≤ 1000) Each of the next t lines contain three space-separated integers:ni, li, ri (1 ≤ ni, li, ri ≤ 109li ≤ ri).

Output

For each query print on a single line: either "Yes", if Alexey can enter the university, or "No" otherwise.

Sample test(s)
input
2
5 2 3
6 4 5
output
Yes
No

大意;给三个数,n,l,r,使用l到r中的数,每个数可以使用任意多次,使得和恰好为n

题解:数据这么大,肯定不是什么乱七八糟的算法,应该是道思维题,然后就yy,可以发现如果n如果在区间内肯定有k*l<=n<=k*r,那么k是多大呢,k肯定满足n/l<=k<=n/r+1,那么只要设a=n/l,b=n/r+1,如果a*r<n且b*l>n就应该输出no,否则yes。,。,逗比的wa at test 1一发。、。、。、。、

代码如下:

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
#define INF 0x7fffffff
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,r,l;
        scanf("%d%d%d",&n,&l,&r);
        if(n<l)
        {
            printf("No\n");
            continue;
        }
        int a=n/l,b=n/r;
        if(r*a<n&&b*l+l>n)
        {
            printf("No\n");
            continue;
        }
        printf("Yes\n");
    }
    return 0;
}
C题待续。,。。,。

D题:http://codeforces.com/problemset/problem/396/B

B. On Sum of Fractions
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's assume that

  • v(n) is the largest prime number, that does not exceed n;
  • u(n) is the smallest prime number strictly greater than n.

Find .

Input

The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases.

Each of the following t lines of the input contains integer n (2 ≤ n ≤ 109).

Output

Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.

Sample test(s)
input
2
2
3
output
1/6
7/30
参考题解:http://codeforces.com/blog/entry/10961

这道题比赛时没有思路,,。只感觉应该是找规律,但太弱没能找出来,比赛完了看了题解才明白。,,。。

题解先证明了当n+1=p(p是素数)的和是1/2-1/p,那么可以计算出当n为任意数的结果,暴力找出离n最近的素数,x<=n<y,那么和应该就是(1/2-1/y)-(y-n-1)/(xy),通分可得分母=2*x*y,分子=(y-2)*x-(y-n-1)

代码如下:

/**
 * @author neko01
 */
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
#define INF 0x7fffffff
bool isprime(int x)
{
    for(int i=2;i*i<=x;i++)
        if(x%i==0)
            return false;
    return true;
}
LL gao(LL a,LL b)
{
    if(a<b)
        swap(a,b);
    if(b==0)
        return a;
    return gao(b,a%b);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        LL n,x,y;
        scanf("%lld",&n);
        x=y=n;
        while(1)
        {
            if(isprime(x))
                break;
            x--;
        }
        y++;
        while(1)
        {
            if(isprime(y))
                break;
            y++;
        }
        LL q=2*x*y,p=x*y-2*x-2*y+2*n+2;
        LL gcd=gao(q,p);
        printf("%I64d/%I64d\n",p/gcd,q/gcd);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值