Comet OJ - Contest #4
题目指路:https://www.cometoj.com/contest/39
就写了一道签到题,第二题死活想不出来,真的丢人
附上大佬的题解:https://www.cnblogs.com/JHSeng/p/10920645.html
A、(签到题)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
int t,a[6],b[20];
cin>>t;
while(t--){
int max=0;
int j;
memset(b,0,sizeof(b));
for(int i=0;i<5;i++){
cin>>a[i];
if(a[i]==1) b[1]++;
if(a[i]==2) b[2]++;
if(a[i]==3) b[3]++;
if(a[i]==4) b[4]++;
if(a[i]==5) b[5]++;
}
for(int i=1;i<=5;i++)
{
if(max<b[i]){
max=b[i];
j=i;
}
}
cout<<j<<endl;
}
return 0;
}
B、奇偶性(找规律题)
理解题意花了好多时间,结果告诉我居然是找规律?!
感谢大佬的思路:https://www.cnblogs.com/Carered/p/10920590.html
附上我的超时代码,起码也是能整出来的,以后作为教训吧,不要老是想着直球。。。
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=100;
int a[maxn];
int main(){
int t,l,r,k,sum;
int prom;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&l,&r,&k);
sum=0;
memset(a,0,sizeof(a));
a[0]=1;
for(int i=l;i<=r;i++){
for(int j=1;j<=k;j++){
if(i<k)
a[i]=1;
else
a[i]+=a[i-j];
}
prom=a[i]%2;
sum+=prom;
//printf("%d %d",prom,sum);
}
// for(int i=l;i<=r;i++)
// printf("%d ",a[i]);
printf("%d\n",sum);
}
return 0;
}
AC代码:(来自 https://www.cnblogs.com/JHSeng/p/10920645.html)
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
long long l,r,k;
cin >> n;
while(n--)
{
scanf("%lld%lld%lld",&l,&r,&k);
long long ans = 0;
if(k % 2 == 0)
{if(k >= r)
{
if(r == k)
ans = r - l;
else
ans = r - l + 1;
}
else if(k < l)
{
long long ll,rr;
ll = l - ((l - k) / (k + 1) + 1);
rr = r - ((r - k) / (k + 1) + 1);
ans = rr - ll + 1;
}
else
{
ans = r - ((r - k) / (k + 1) + 1) - l + 1;
if(l == k) ans += 1;
}
}
else
{
ans = r - l + 1;
}
printf("%lld\n",ans);
}
return 0;
}
剩下的题目有空再补
虽然我觉得有空是不太可能了,嘛还是看看大佬的题解度日好了