星期一到现在一共做了四道题吧,提交了三道,只过了两道,还一道没调出来。。。上课了空闲时间有点少吧
Who Gets the Most Candies?
Time Limit : 10000/5000ms (Java/Other) Memory Limit : 262144/131072K (Java/Other)
Total Submission(s) : 43 Accepted Submission(s) : 17
N children are sitting in a circle to play a game.
The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The game starts from the K-th child, who tells all the others the integer on his card and jumps out of the circle. The integer on his card tells the next child to jump out. Let A denote the integer. If A is positive, the next child will be the A-th child to the left. If A is negative, the next child will be the (−A)-th child to the right.
The game lasts until all children have jumped out of the circle. During the game, the p-th child jumping out will get F(p) candies where F(p) is the number of positive integers that perfectly divide p. Who gets the most candies?
4 2 Tom 2 Jack 4 Mary -1 Sam 1
Sam 3
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,k;
int s[500005],f,ss;
struct Name
{
char name[11];
int v;
}a[500005];
struct F
{
int l,r,sum;
}tree[2000005];
void build(int l,int r,int p)
{
tree[p].l=l;
tree[p].r=r;
tree[p].sum=r-l+1;
if(l==r)
return;
int mid=(l+r)/2;
build(l,mid,p*2);
build(mid+1,r,p*2+1);
}
int find(int rt,int p)
{
tree[p].sum--;
if(tree[p].l==tree[p].r)
return tree[p].l;
if(rt<=tree[p*2].sum)
find(rt,p*2);
else
find(rt-tree[p*2].sum,p*2+1);
}
int main()
{
int i,j;
while(cin>>n>>k)
{
for(i=1;i<=n;i++)
scanf("%s%d",a[i].name,&a[i].v);
build(1,n,1);
memset(s,0,sizeof(s));
for(i=1;i<=n;i++)
{
s[i]++;
for(j=i*2;j<=n;j+=i)
s[j]++;
}
ss=s[1],f=1;
for(i=2;i<=n;i++)
if(ss<s[i])
{
ss=s[i];
f=i;
}
int ff=f,q;
for(i=0;i<ff;i++)
{
n--;
q=find(k,1);
if(n==0)
break;
if(a[q].v>0)
k=(k+a[q].v-2)%n+1;
else
k=((k+a[q].v-1)%n+n)%n+1;
}
printf("%s %d\n",a[q].name,ss);
}
}
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 33 Accepted Submission(s) : 23
1 5 2 3 1 2 5 4 1 5 2 4
1 2
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct f
{
int l,r,p;
}tree[100005];
int ss[100005],c[100005],a[100005],b[100005],n;
bool cmp(f aa,f bb)
{
return aa.r<bb.r;
}
int lowbit(int aa)
{
return aa&(-aa);
}
void add(int p,int v)
{
while(p<=n)
{
c[p]+=v;
p+=lowbit(p);
}
}
int sum(int p)
{
int s=0;
while(p>0)
{
s+=c[p];
p-=lowbit(p);
}
return s;
}
int main()
{
int t,i,j,f,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[a[i]]=i;
}
for(i=0;i<m;i++)
{
scanf("%d%d",&tree[i].l,&tree[i].r);
tree[i].p=i;
}
sort(tree,tree+m,cmp);
memset(c,0,sizeof(c));
f=0;
for(i=1;i<=n;i++)
{
add(i,1);
if(a[i]>1&&b[a[i]-1]<i)
add(b[a[i]-1],-1);
if(a[i]<n&&b[a[i]+1]<i)
add(b[a[i]+1],-1);
while(f<m&&tree[f].r==i)
{
ss[tree[f].p]=sum(tree[f].r)-sum(tree[f].l-1);
f++;
}
}
for(i=0;i<m;i++)
printf("%d\n",ss[i]);
}
return 0;
}
还有1014题,今天上实验课的时候看了看这道题,感觉不用线段树就可以,然后写了下,没过,明天再试下,再过不了再用线段树,看了下大佬们的题解,是从后往前,而我是从前我往后,我是想先排序左边界,然后这一点与后面就会有6种情况,然后每种情况讨论,然后查看是否该段能否被覆盖,不过也许会超时,不过总得试过了才知道。。。