思路:强模拟…考试时还有点虚了…
思路:从t倒着dfs一遍到s,标记经过的点,再判断这些点是否满足题意,最后最短路跑一下…
思路:一看到a的范围还有的懵逼了,但仔细一想,只要满足这个式子的和为0,且运算中只有‘+’和‘*’,并没有‘/’,那就果断可以mod,即边读边mod,暴力O(n*m),然而这样还是要被卡掉了,正解应该是多来几个质数去mod,才不容易被卡掉(人品)。
#include
#define REP(i,f,t) for(int i=(f),i##_end_=(t);i<=i##_end_;i++)
#define DREP(i,f,t) for(int i=(f),i##_end_=(t);i>=i##_end_;i--)
#define LL long long
#define N 105
#define M 1000005
#define Mod 1000000007
using namespace std;
int n,m;
int Ans[M];
struct p30{
int A[N];
bool check(int x){
LL res=1LL*A[n]*x;
DREP(i,n-1,1)res+=A[i],res*=x;
res+=A[0];
return !res;
}
void solve(){
int cnt=0;
REP(i,0,n)scanf("%d",&A[i]);
REP(i,1,m)if(check(i))Ans[++cnt]=i;
printf("%d\n",cnt);
REP(i,1,cnt)printf("%d\n",Ans[i]);
}
}p30;
struct p70{
LL A[N];
LL Rd(){
LL res=0,f=1;char c;
while((c=getchar())<48)if(c=='-')f=-1;
do res=(res<<1)+(res<<3)+(c^48),res%=Mod;
while((c=getchar())>47);
return res*f;
}
bool check(int x){
LL res=0;
DREP(i,n,0)res=res*1LL*x+A[i],res%=Mod;
return !res;
}
void solve(){
int cnt=0;
REP(i,0,n)A[i]=Rd();
REP(i,1,m)if(check(i))Ans[++cnt]=i;
printf("%d\n",cnt);
REP(i,1,cnt)printf("%d\n",Ans[i]);
}
}p70;
struct p100{
char s[10005];
int A[N][5],cnt;
bool mark[100005][5];
int p[5]={10007,10917,30071};
bool calc(int x, int j){
LL res=0;
DREP(i,n,0)res=(res*x+A[i][j])%p[j];
return res!=0;
}
void solve(){
REP(i,0,n){
scanf("%s",s);
int len=strlen(s),f=1;
REP(l,0,len-1){
if(s[l]=='-'){f=-1;continue;}
REP(j,0,2)A[i][j]=(A[i][j]*10+s[l]-'0')%p[j];
}
if(f==-1)REP(j,0,2)A[i][j]=p[j]-A[i][j];
}
REP(j,0,2)
REP(i,0,p[j]-1)
mark[i][j]=calc(i,j);
REP(i,1,m){
bool flag=1;
REP(j,0,2)
if(mark[i%p[j]][j]){
flag=0;
break;
}
if(flag)Ans[++cnt]=i;
}
printf("%d\n", cnt);
REP(i,1,cnt)printf("%d\n",Ans[i]);
}
}p100;
int main(){
// freopen("equation.in","r",stdin);
// freopen("equation.out","w",stdout);
scanf("%d%d",&n,&m);
if(n<=2)p30.solve();
else if(m<=10000)p70.solve();
else p100.solve();
return 0;
}
小结:今天考得还可以,没有犯低级错误了,该切分的也切了,希望要再接再厉!