基础练习二 (12道)

A - Divisibility
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.

Input

The only line contains three space-separated integers ka and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

Output

Print the required number.

Sample Input

Input
1 1 10
Output
10
Input
2 -4 4
Output
5

WA了无数次的题,最后还让同学又揪的错…………

分情况:

a>=0,b>=0

a<=0,b<=0:  a,b化成正数时a>b……

a<0,b>0:   b/k-a/k+1

ZZZZZ

#include<cstdio>
int main()
{
	long long k,a,b,ans;
	while(~scanf("%lld%lld%lld",&k,&a,&b))
	{
	
		if(b<=0)
		{
			a=-a;
			b=-b;
			ans=a/k-b/k;
			if(b%k==0)
				ans++;
		}
		else if(a>=0)
		{
			ans=b/k-a/k;
			if(a%k==0)
				ans++;
		}
		else
		{
			ans=b/k-a/k+1;
		}
		printf("%lld\n",ans);
	}
	return 0;
}



B - Tricky Sumhttp://acm.hust.edu.cn/vjudge/contest/123213#problem/B

题解:可以先求出1-n的和,再减去1-n中 2的次方的和*2

ac代码:

#include<cstdio>
#include<cmath>
int main()
{
	int t;
	long long n,sum,k,m;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld",&n);
		sum=(n+1)*n/2;
		long long a[1000];
		a[0]=1;m=1;
		for(int i=1;i<1000;i++)		//1--n中2的次方的和 
		{
			m=m*2;	//记录2的次方 
			if(m>n)
			{
				k=a[i-1];
				break;
			}
			else
				a[i]=a[i-1]+m;	//求和 
		}
		sum=sum-2*k;
		printf("%lld\n",sum);		 
	}
	return 0;
}

C -  Patrick and Shoppinghttp://acm.hust.edu.cn/vjudge/contest/123213#problem/C

题解:由于数据少  列出可能的路径(一共六种),和最小的即所求。

D - Uncowed Forceshttp://acm.hust.edu.cn/vjudge/contest/123213#problem/D

题解:本来是挺简单的一个题,按照题意列公式就行,编译器不知道咋的开始就是编译不出来…………

ac代码:

#include<cstdio>
int main()
{
	int m[10],w[10],h1,h2,s[10],y;
	int x[5]={500,1000,1500,2000,2500};
	while(~scanf("%d",&m[0]))
	{
		for(int i=1;i<5;i++)
			scanf("%d",&m[i]);
		for(int i=0;i<5;i++)
			scanf("%d",&w[i]);
		scanf("%d%d",&h1,&h2);
		int sum=h1*100-h2*50; 
		for(int i=0;i<5;i++)
		{
			s[i]=x[i]-x[i]/250*m[i]-w[i]*50;
			y=x[i]*3/10;
			if(s[i]<y)
				sum=sum+y;
			else
				sum=sum+s[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}
E - The Text Splitting
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
[ps:理清思路]

Description

You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.

For example, the string "Hello" for p = 2q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".

Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test).

Input

The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100).

The second line contains the string s consists of lowercase and uppercase latin letters and digits.

Output

If it's impossible to split the string s to the strings of length p and q print the only number "-1".

Otherwise in the first line print integer k — the number of strings in partition of s.

Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s — from left to right.

If there are several solutions print any of them.

Sample Input

Input
5 2 3
Hello
Output
2
He
llo
Input
10 9 5
Codeforces
Output
2
Codef
orces
Input
6 4 5
Privet
Output
-1
Input
8 1 1
abacabac
Output
8
a
b
a
c
a
b
a
c

p*x+q*y==n  数据小  枚举解方程

*****ac

#include<cstdio>
#include<cstring>
int main()
{
	int n,p,q,m,ans1,ans2;
	char s[110];
	while(~scanf("%d%d%d",&n,&p,&q))
	{
		scanf("%s",s);
		if(n%p==0)
		{
			m=0;
			printf("%d\n",n/p);
			for(int i=0;i<n;i++)
			{
				printf("%c",s[i]);
				m++;
				if(m==p)
				{
					printf("\n");
					m=0;
				}
					
			}
		}
		else if(n%q==0)
		{
			m=0;
			printf("%d\n",n/q);
			for(int i=0;i<n;i++)
			{
				printf("%c",s[i]);
				m++;
				if(m==q)
				{
					printf("\n");
					m=0;
				}
					
			}
		}
		else
		{
			int f=0;
			for(int i=1;i<n;i++)
			{
				for(int j=1;j<n;j++)
				{
					if(p*i+q*j==n)
					{
						f=1;
						ans1=i;
						ans2=j;
						break;
					}
				}
				if(f)
					break;
			}
			if(f)
			{
				printf("%d\n",ans1+ans2);
				m=0;
				for(int i=0;i<ans1*p;i++)
				{
					printf("%c",s[i]);
					m++;
					if(m==p)
					{
						printf("\n");
						m=0;
					}
				}
				for(int j=ans1*p;j<n;j++)
				{
					printf("%c",s[j]);
					m++;
					if(m==q)
					{
						printf("\n");
						m=0;
					}
				}
			}
			else
				printf("-1\n");
		}
	}
	return 0;
}

F -  Pasha and Stickhttp://acm.hust.edu.cn/vjudge/contest/123213#problem/F

题解:题意是给一个数,问能构成多少矩形(不可以是正方形)

首先小于等于5时和n为奇数时 不可能,输出0,然后按照对边相等(n/2)-1)/2……

G - New Year and Dayshttp://acm.hust.edu.cn/vjudge/contest/123213#problem/G

题解:2016年共366天 、二月29  、1月1日星期五,下面就是常识了

H - Bulbshttp://acm.hust.edu.cn/vjudge/contest/123213#problem/H

数组下标 标记亮的灯,再遍历1-m 看是否有没亮的

I - Restauranthttp://acm.hust.edu.cn/vjudge/contest/123213#problem/I【贪心  区间问题】

算掌握了

ac

#include<cstdio>
#include<algorithm>
using namespace std;
struct Node
{
	int ts,te;
}order[500000+10];
bool cmp(Node a,Node b)
{
	if(a.te==b.te)
		return a.ts<b.ts;
	return a.te<b.te;
}
int main()
{
	int n;
	int en;
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&order[i].ts,&order[i].te);			
		}
		sort(order,order+n,cmp);
		en=order[0].te;
		int ans=1;
		for(int i=1;i<n;i++)
		{
			if(en<order[i].ts)
			{
				ans++;
				en=order[i].te;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

HDD is Outdated Technologyhttp://acm.hust.edu.cn/vjudge/contest/123213#problem/J

嗯  还是下标标记**

#include<cstdio>
int main()
{
	int n,a[500000+10],b;
	long long sum;
	while(~scanf("%d",&n))
	{
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&b);
			a[b]=i;			
		 } 
		 sum=0;
		 for(int i=2;i<=n;i++)
		 {
		 	if(a[i]-a[i-1]>0)
		 		sum+=a[i]-a[i-1];
		 	else
		 		sum-=a[i]-a[i-1];
		 }
		 printf("%lld\n",sum);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值