题解 CF78B 【Easter Eggs】
GusyNight
2019-05-03 14:37:59
这道题.....
不说,先读题,记住**不管在什么时候,读题第一!**
```
复活节兔子把n个蛋围成了一个圆圈。她打算给它们上色。
每一个蛋都要被涂上红橙黄绿蓝靛紫七色中的一个颜色,并满足如下条件:
1、每一种颜色都必须用上
2、任何四个相连的蛋都要涂上不同的颜色。
帮助复活节兔子涂上颜色,当然,这肯定是有解的!
输入:
一行:n(7<=n<=100)
输出:
一行:用下列字符表示所涂上的颜色:R(红red),O(橙orange),Y(黄:yellow),G(绿green),B(蓝blue),I(靛indigo),V(紫violet)
注意:如果存在多个答案,输出其中一种即可
```
大意就是
```
有n个数,每个数都要表上号1~7中的一个,每4个数不能重复,七个号都要有~~~
```
我的思考
```
貌似只要我前面不停的输出"RYOG"最后一次输出"BIV"就可以了~~~
```
循环
```cpp
for(int i=1;i<=n;i++){
if(i%4==1){printf("R");}
if(i%4==2){printf("Y");}
if(i%4==3){printf("O");}
if(i%4==0){printf("G");}
}
```
```
但是这样交上去在第2个就会WA
```
***仔细思考,发现是我的顺序不对真正的顺序是 "ROYG" 在最后输出 "BIV"***
**代码**
```cpp
#include<bits/stdc++.h>
#define I int
#define L long long
#define C char
#define S string
#define B bool
#define Max 100000009
#define Mid 1000009
#define Sml 10009
#define Lit 109
using namespace std;
inline I read(){
char c=getchar();
I x=0;
B f=0;
while(!isdigit(c))f^=!(c^45),c=getchar();
while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f)x=-x;return x;
}
int n;
char colour[8]={' ','R','O','Y','G','B','I','V'};
int main(){
n=read();
for(int i=1;i<=4;i++){
printf("%c",colour[i]);
}
return 0;
n-=7;
for(int i=1;i<=n;i++){
if(i%4==1){printf("R");}
if(i%4==2){printf("O");}
if(i%4==3){printf("Y");}
if(i%4==0){printf("G");}
}
puts("BIV");
return 0;
}
```
**还是WA这次实在第一个点**
**反思ing**
```cpp
#include<bits/stdc++.h>
#define I int
#define L long long
#define C char
#define S string
#define B bool
#define Max 100000009
#define Mid 1000009
#define Sml 10009
#define Lit 109
using namespace std;
inline I read(){
char c=getchar();
I x=0;
B f=0;
while(!isdigit(c))f^=!(c^45),c=getchar();
while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f)x=-x;return x;
}
int n;
char colour[8]={' ','R','O','Y','G','B','I','V'};
int main(){
n=read();
for(int i=1;i<=4;i++){
printf("%c",colour[i]);
}
return 0;
n-=7;
for(int i=1;i<=n;i++){
if(i%4==1){printf("R");}
if(i%4==2){printf("O");}
if(i%4==3){printf("Y");}
if(i%4==0){printf("G");}
}
puts("BIV");
return 0;
}
```
**看我这么口爱,不点个赞再走?**