1/0
0/1
2/1
样例描述
这些多项式分别为
f(x) = 2x
f(x)=2x
g(x) = 1
g(x)=1
f(x) = 1
f(x)=1
g(x) = 2x
g(x)=2x
f(x) = 4x + 2
f(x)=4x+2
g(x) = 2x + 1
g(x)=2x+1
思路:上下两个数组从后往前比较一下0出现的位置就行了,就是找到第一个非0位置!:) 答案要么是0/1,要么是1/0,要么就是一个上下需要约分一下的比值
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 2000000000
#define eps 1e-8
#define pi 3.141592653589793
const LL mod = 1e9+7;
struct node{
int x,y;
}p[1001];
int main()
{
int _;
for(scanf("%d",&_);_--;){
int n;
scanf("%d",&n);
int Min = 10000000,Max = 0;
for(int i = 0 ; i < n ; i++){
scanf("%d",&p[i].x);
}
for(int i = 0 ; i < n ; i++){
scanf("%d",&p[i].y);
}
for(int i = n-1 ; i >= 0 ;i --){
if(p[i].x == 0 && p[i].y == 0)continue;
if(p[i].x == 0 && p[i].y != 0){
puts("0/1");break;
}else if(p[i].x != 0 && p[i].y == 0){
puts("1/0");break;
}else{
LL a = __gcd(p[i].x,p[i].y);
printf("%lld/%lld\n",p[i].x*1LL/a,p[i].y*1LL/a);
break;
}//判断非零出现的位置,三种情况
}
}
}
E:Seq
Seq
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
思路:打个表发现从n从4开始,6个一循环的。每个循环节里面都有规律可以找。比如除以二,减去一之类的。注意用long long
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define INF 2000000000
#define eps 1e-8
#define pi 3.141592653589793
const LL mod = 1e9+7;
int main()
{
/*
LL a[1112];
int n = 150;
a[1] = 1LL;
for(int i = 2 ; i <= n ; i ++){
LL sum = 0;
for(int j = 1 ; j <= i-1 ; j ++){
sum += a[j]*j;
sum %= i;
}
a[i] = sum;
if( sum + 1 == i )printf("---");
printf("%d : %lld \n",i,sum);
}
*/
int _;
for(scanf("%d",&_);_--;){
LL n;
scanf("%I64d",&n);
if(n == 1|| n == 2){
printf("1\n");
}else if(n == 3){
printf("0\n");
}else{
LL k = n-4;
if(k%6 == 0){
printf("%I64d\n",n-1);
}
else if(k%6==1){
printf("%I64d\n",n/6);
}
else if(k%6==2){
printf("%I64d\n",n/2);
}
else if(k%6==3){
printf("%I64d\n",n-(k/6+1)*2);
}
else if(k%6==4){
printf("%I64d\n",n/2);
}
else if(k%6==5){
printf("%I64d\n",k/6+1);
}
}
}
}/*
*/