T1:
Explanation:
60 PTS Backpack + program output during the exam... (Expected score 50?
Is it stable or good?
100pts:
Find out the prefix sum, first module n out, sweep to see if there is a prefix sum is 0, if there is a prefix sum is 0, then directly output 1~x (prefix sum is 0)
If the sum of prefixes is zero, there are N prefixes and the range of values is 1-N-1, that is to say, at least two prefixes and the sum of them are the same.
What's the significance of this? If sum [a] = sum[b] (a < = b), then sum[b] sum[a]=0
What does that mean? That's not to say a+1~b comes up with a n n, just output it directly.
This is urinary... It's very similar to the C question of CF.
Code:
60pts
#include <cstdio>
#define N 1000005
using namespace std;
struct hh{int x,id;}a[N];
bool f[N];int tot,ans[N];
inline int in()
{
char ch=getchar();int x=0,f=1;
while (ch>'9'|| ch<'0') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
void find(int z,int up)
{
if (z==0) return;
for (int i=up;i>=1;i--)
if (f[z-a[i].x])
{
ans[++tot]=a[i].id;
find(z-a[i].x,i-1);
break;
}
}
int main()
{
freopen("set.in","r",stdin);
freopen("set.out","w",stdout);
int n,i,j;
n=in();
for (i=1;i<=n;i++) {a[i].x=in(); a[i].id=i;}
for (i=1;i<=n;i++)
{
a[i].x%=n;
if (a[i].x==0) {printf("1\n%d",a[i].id);return 0;}
}
bool vv=0;f[0]=1;
for (i=1;i<=n;i++)
{
for (j=n;j>=a[i].x;j--)
{
f[j]=f[j] || f[j-a[i].x];
if (f[n]){vv=1;break;}
}
if (vv) break;
}
if (!vv){printf("-1");return 0;}
else
{
find(n,i);
printf("%d\n",tot);
for (i=1;i<tot;i++) printf("%d ",ans[i]);
printf("%d",ans[tot]);
}
}
100pts
#include <cstdio>
#include <algorithm>
#define N 1000005
using namespace std;
int sum[N],a[N],c[N];
inline int in()
{
char ch=getchar();int x=0,f=1;
while (ch>'9'|| ch<'0') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int main()
{
freopen("set.in","r",stdin);
freopen("set.out","w",stdout);
int n,i,j;
n=in();
for (i=1;i<=n;i++)
{
a[i]=in();
a[i]%=n;sum[i]=(a[i]+sum[i-1])%n;
}
for (i=1;i<=n;i++)
if (!sum[i])
{
printf("%d\n",i);
for (j=1;j<=i;j++)
printf("%d ",j);
return 0;
}
for (i=1;i<=n;i++)
{
if (c[sum[i]])
{
printf("%d\n",i-c[sum[i]]);
for (j=c[sum[i]]+1;j<=i;j++)
printf("%d ",j);
return 0;
}
c[sum[i]]=i;
}
printf("%d",-1);
}
T2:
Explanation:
This question is the original one...
That's to find the modulus of n numbers. If there's no modulus, it's zero.
If there is a number, it is a number * 2 - the total number - 1
Because the number that can be paired is 2*num (the number of modes) - n (the total number) - 1, that's it? It's to put another mode number on the first place.
Code:
#include <cstdio>
#include <algorithm>
#define N 10005
using namespace std;
int cont[N],x[N],y[N],z[N],stack[N],cnt;
inline int in()
{
char ch=getchar();int x=0,f=1;
while (ch>'9'|| ch<'0') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
int main()
{
freopen("read.in","r",stdin);
freopen("read.out","w",stdout);
int n=0,i,j,m,k;
m=in();k=in();
for (i=1;i<=m;i++) cont[i]=in();
for (i=1;i<=m;i++) x[i]=in();
for (i=1;i<=m;i++) y[i]=in();
for (i=1;i<=m;i++) z[i]=in();
int s=(1<<k)-1;int a=-1,now=0;
for (i=1;i<=m;i++)
{
if (!now) a=x[i];
if (x[i]!=a) now--;else now++;
long long last=x[i];
for (int j=1;j<cont[i];j++)
{
last=(last*y[i]+z[i])&s;
if (!now) a=last;
if (last!=a) now--;else now++;
}
}
now=0;
for (i=1;i<=m;i++)
{
++n;
if (x[i]==a) now++;
long long last=x[i];
for (int j=1;j<cont[i];j++)
{
last=(last*y[i]+z[i])&s;
++n;
if (last==a) now++;
}
}
now=now*2-n;
if (now<0) printf("0");else printf("%d",now-1);
}
Make complaints:
Just finished the exam, loser: Ah, the original topic of T2
Meow Meow Meow: What's the problem?
loser: bzoj2456
Meow and Meow (Enter bzoj excitedly): 2-4-5-6
Meow meow meow:...... Meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow.
Meow meow: This question... I've done it.
Then take a closer look. woc is really the topic. It just changed shape.
... Goodbye,.jpg.
Is the spj of T1 written?
Then there are four approaches to T1:
Output - 1; Expected score 10; Actual score 0
n^2dp; expected score 50; actual score 60
Scientific problem solving; Expected score 100; Actual score 100
Nothing output; expected score 0; actual score 100
hahaha