分情况:
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;
}
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;
}