OutputPrint the word "yes" if 3 divide evenly into F(n).
(3平均分,就是被三整除)
Print the word "no" if not.
Sample Input
0 1 2 3 4 5Sample Output
no no yes no no no
#include<bits/stdc++.h> using namespace std; #define N 1000000 typedef long long ll; using namespace std; ll num[N]; void dabiao() { num[0]=7%3; num[1]=11%3; for(int i=2;i<=1000000;++i) num[i]=(num[i-1]+num[i-2])%3; } int main() { dabiao(); int n; while(cin>>n) { if(num[n]==0) cout<<"yes"<<endl; else cout<<"no"<<endl;} return 0; }//关键在于打表的时候对每次都对3取余。else 数据会爆。
也可以找规律做
- #include<iostream>
- using namespace std;
- int main()
- {// 7 11 18|. 29 47 76 123|. 199 322 521 843|. 1364 2207 3571 5578|.
- // 2 6 10...
- //综上所述可知规律
- //一般的思维会想着先把数列写出来,然后进行作除判断,但是这道题有其规律性
- int n ;
- while(cin>>n)
- {
- if(n%4 == 2)
- {
- cout<<"yes"<<endl;
- }
- else
- {
- cout<<"no"<<endl;
- }
- }
- return 0;
- }
-
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.Input
Is an escape possible? If yes, how long will it take?
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).Output
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.Each maze generates one line of output. If it is possible to reach the exit, print a line of the formSample Input
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
3 4 5 S.... .###. .##.. ###.# ##### ##### ##.## ##... ##### ##### #.### ####E 1 3 3 S## #E# ### 0 0 0
Sample OutputEscaped in 11 minute(s). Trapped!
#include <stdio.h>
#include <queue>
#include<iostream>
#include<cstring>
using namespace std;
char mmp[35][35][35];
int vis[35][35][35];
int k,n,m,sx,sy,sz,ex,ey,ez;
int to[6][3]={{0,0,1},{0,0,-1},{0,1,0},{0,-1,0},{1,0,0},{-1,0,0}};
struct node
{
int x,y,z,step;
};
int check(int x,int y,int z)
{
if(x<0 || y<0 || z<0 || x>=k || y>=n || z>=m)
return 1;
else if(mmp[x][y][z] == '#')
return 1;
else if(vis[x][y][z])
return 1;
return 0;
}
int bfs()
{
int i;node a,next;
queue<node>Q;
a.x=sx,a.y=sy,a.z=sz;
a.step=0;
vis[sx][sy][sz]=1;
Q.push(a);
while(!Q.empty())
{
a=Q.front();
Q.pop();
if(a.x==ex&&a.y==ey&&a.z==ez)
return a.step;
for(i=0;i<6;i++)
{
next=a;
next.x=a.x+to[i][0];
next.y=a.y+to[i][1];
next.z=a.z+to[i][2];
if(check(next.x,next.y,next.z))
continue;
vis[next.x][next.y][next.z]=1;
next.step=a.step+1;
Q.push(next);
}
}
return 0;
}
int main()
{
int i,j,r;
while(scanf("%d%d%d",&k,&n,&m),n+m+k)
{
for(i = 0; i<k; i++)
{
for(j = 0; j<n; j++)
{
scanf("%s",mmp[i][j]);
for(r = 0; r<m; r++)
{
if(mmp[i][j][r] == 'S')
{
sx = i,sy = j,sz = r;
}
else if(mmp[i][j][r] == 'E')
{
ex = i,ey = j,ez = r;
}
}
}
}
memset(vis,0,sizeof(vis));
int ans;
ans = bfs();
if(ans)
printf("Escaped in %d minute(s).\n",ans);
else
printf("Trapped!\n");
}
return 0; - }
There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Now you are given two integers A and B, you have to find the number of integers from Ath number to Bth (inclusive) number, which are divisible by 3.
For example, let A = 3. B = 5. So, the numbers in the sequence are, 123, 1234, 12345. And 123, 12345 are divisible by 3. So, the result is 2.
InputInput starts with an integer T (≤ 10000), denoting the number of test cases.
Each case contains two integers A and B (1 ≤ A ≤ B < 231) in a line.
OutputFor each case, print the case number and the total numbers in the sequence between Ath and Bthwhich are divisible by 3.
Sample Input2
3 5
10 110
Sample OutputCase 1: 2
Case 2: 67
#include<cstdio>#include<cstring>
#include<algorithm>
using namespace std;
long long f(long long n)
{
long long s=n/3;
long long sum;
if(n%3==1||n%3==0)
sum=s*2;
else
sum=s*2+1;
return sum;
}
int main()
{
int t,k=1;
long long a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld",&a,&b);
long long num=0;
num=f(b)-f(a)+(a%3==1?0:1);
printf("Case %d: ",k++);
printf("%lld\n",num);
}
return 0;
}
The array is [1 3 -1 -3 5 3 6 7], and k is 3.
Window position | Minimum value | Maximum value |
---|---|---|
[1 3 -1] -3 5 3 6 7 | -1 | 3 |
1 [3 -1 -3] 5 3 6 7 | -3 | 3 |
1 3 [-1 -3 5] 3 6 7 | -3 | 5 |
1 3 -1 [-3 5 3] 6 7 | -3 | 5 |
1 3 -1 -3 [5 3 6] 7 | 3 | 6 |
1 3 -1 -3 5 [3 6 7] | 3 | 7 |
Your task is to determine the maximum and minimum values in the sliding window at each position.
8 3 1 3 -1 -3 5 3 6 7Sample Output
-1 -3 -3 -3 3 3 3 3 5 5 6 7