我傻掉了,没AK
我自己出的题目和题单(洛谷没有)传送门
T1
直接排序,然后跑next_permutation,把每种序列都算一下。
代码:
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pi 3.1415926535897932384626
using namespace std;
#define int long long
int n=7;
int Ar[100];
bool check()
{
int a=Ar[1],b=Ar[2],c=Ar[3];
if(Ar[4]==a+b && Ar[5]==b+c && Ar[6]==a+c && Ar[7]==a+b+c) return true;
return false;
}
signed main()
{
for(int i=1;i<=n;i++)
{
scanf("%lld",&Ar[i]);
}
sort(Ar+1,Ar+1+n);
do{
if(check())
{
sort(Ar+1,Ar+4);
printf("%lld %lld %lld\n",Ar[1],Ar[2],Ar[3]);
return 0;
}
}while(next_permutation(Ar+1,Ar+1+n));
return 0;
}
T2
存前缀和,然后根据 s u m [ i ] [ j ] = b e f o r e [ j ] − b e f o r e [ i − 1 ] sum[i][j]=before[j]-before[i-1] sum[i][j]=before[j]−before[i−1]
s u m [ i ] [ j ] sum[i][j] sum[i][j]是从 i i i到 j j j的和, b e f o r e [ i ] before[i] before[i]是从 1 1 1到 i i i的和。
还要小心精度问题
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pi 3.1415926535897932384626
using namespace std;
#define int long long
int Ar[110];
int bef[110];
int sum[110][110];
signed main()
{
int n;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&Ar[i]);
bef[i]=bef[i-1]+Ar[i];
}
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
int num=j-i+1;
int sum=bef[j]-bef[i-1];
double Pin=sum*1.0/num;
int l=i,r=j;
for(int k=l;k<=r;k++)
{
if(Ar[k]*1.0==Pin)
{
cnt++;
break;
}
}
}
}
printf("%lld",cnt);
return 0;
}
T3
我大意了,看了一眼, 1 ≤ x , y ≤ 1 0 9 1\le x,y \le 10^9 1≤x,y≤109?/jk
只要你学过OI,你就会发现,硬模拟肯定是过不去的,只能过部分点。
那咋办呢?
我们可在每次走的时候判断两个牛之间是否能碰到,并记录
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define pi 3.1415926535897932384626
using namespace std;
const int Maxn=100;
struct Node{
int stoped;
int x,y;
char opt;
}Ar[Maxn];
int n;
int T[Maxn];
int Hits(int x,int y,int now)
{
Node i=Ar[x],j=Ar[y];
if(i.opt==j.opt)
{
return INF;
}
if(i.opt=='E')
{
swap(i.x,i.y);
swap(j.x,j.y);
}
if(j.y<=i.y)
{
return INF;
}
if(j.stoped==INF)
{
if(i.x<j.x-now || i.x>=j.x+j.y-i.y)
{
return INF;
}
}else{
if(i.x>j.x || i.x<j.x-j.stoped)
{
return INF;
}
}
return now+j.y-i.y;
}
int movenext(int now)
{
int minn=INF;
memset(T,0,sizeof(T));
for(int i=1;i<=n;i++)
{
T[i]=INF;
if(Ar[i].stoped==INF)
{
for(int j=1;j<=n;j++)
{
int Time=Hits(i,j,now);
T[i]=min(T[i],Time);
}
minn=min(minn,T[i]);
}
}
if(minn==INF)
{
return INF;
}
for(int i=1;i<=n;i++)
{
if(Ar[i].stoped==INF)
{
if(Ar[i].opt=='N')
{
Ar[i].y+=(minn-now);
}else{
Ar[i].x+=(minn-now);
}
}
if(T[i]==minn)
{
Ar[i].stoped=minn;
}
}
return minn;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
cin>>Ar[i].opt;
scanf("%d%d",&Ar[i].x,&Ar[i].y);
Ar[i].stoped=INF;
}
int now=0;
do{
now=movenext(now);
}while(now!=INF);
for(int i=1;i<=n;i++)
{
if(Ar[i].stoped==INF){
puts("Infinity");
}else{
printf("%d\n",Ar[i].stoped);
}
}
return 0;
}