1001 (Logical Reasoning)
Topic: The two options are A, B and C. Now they choose the option and the points they get tell you whether they lie or not.
Idea: Judging the upper and lower limits is enough.
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=80000+5;
char a[N],b[N];
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
scanf("%s\n%s",a,b);
int num=0;
int i;
for(i=0;i<n;i++)
{
if(a[i]==b[i]) num++;
}
int k=0;
if(x>=num&&y>=num)
{
int x1=x-num;
int y1=y-num;
int x2=x1+y1;
if(x2>n-num) k=1;
}
else if(x>=num&&y<num)
{
int x1=x-y;
if(x1>n-num) k=1;
}
else if(x<num&&y>=num)
{
int y1=y-x;
if(y1>n-num) k=1;
}
else if(x<num&&y<num)
k=0;
if(!k) printf("Not lying\n");
else printf("Lying\n");
}
return 0;
}
1003
Question meaning: Give a sequence a, each time you can choose any number from the array b to indicate that you can choose any number from the number with the subscript 1 to n (where n, each time you make a new number n will grow) and make a number with the subscript j at the end of the sequence a. The value of this number is a J - J. Now ask what is the maximum number of the newly produced.
Thought: Sort each time to get the maximum sum can be
#include <cstdio>
#include <algorithm>
#include <iostream>
#define maxn 250010
const int mod=1e9+7;
using namespace std;
int a[maxn],b[maxn],c[maxn],d[maxn],n;
void f()
{
int i,j;
for (i=1;i<=n;i++)
{
scanf("%d",&a[i]);
d[i]=a[i]-i;
}
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
c[n]=d[n];
for(i=n-1;i>0;i--)
c[i]=max(c[i+1],d[i]);
sort(b+1,b+1+n);
int x=c[b[1]];
int ans=x;
for(i=1;i<=n;i++)
c[i]=max(c[i],x-(n+1));
for(i=2;i<=n;i++)
{
x=c[b[i]];
ans+=x;
ans%=mod;
}
printf("%lld\n", ans);
}
int main()
{
while(~scanf("%d",&n))
f();
return 0;
}
1011
Topic: A coordinate of 200 x 200 has n integer points. Ask how many different regular polygons can be formed.
Idea: Just ask for the square (notice the diamond)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 605;
int mp[MAXN][MAXN];
struct Point{
int x, y;
}p[MAXN];
int cmp(Point A, Point B)
{
if(A.x==B.x)return A.y<B.y;
return A.x<B.x;
}
int main()
{
int n;
while(~scanf("%d", &n))
{
memset(mp, 0, sizeof(mp));
for(int i=0; i<n; i++)
{
int x,y;
scanf("%d%d",&x,&y);
p[i].x=(x+300);
p[i].y=(y+300);
mp[p[i].x][p[i].y]=1;
}
sort(p,p+n,cmp);
int sum=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int dx=p[i].x-p[j].x;
int dy=p[j].y-p[i].y;
if(mp[p[i].x+dy][p[i].y+dx]&&mp[p[j].x+dy][p[j].y+dx]) sum++;
}
}
printf("%d\n",sum/2);
}
return 0;
}