ACMEaster Eggs

Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:

  • Each of the seven colors should be used to paint at least one egg.
  • Any four eggs lying sequentially should be painted different colors


        

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
using namespace std;
class List
{
public:

	char val;
	List* prior;
	List* next;
	List(char data = '\0', List* p = NULL, List* q = NULL) { val = data; prior = p; next = q; }
};
char color[7] = { 'R','O','Y','G','B','I','V' };
List* Creat(int n)
{
	List* head = new List('\0', NULL);
	List* last = head;
	for (int i = 0; i < n; i++) {
		List* node = new List;
		node->val = '\0';//表示还没有
		last->next = node;
		node->prior = last;
		last = node;
	}
	last->next = head->next;
	head->prior = last;
	return head;
}
//d be painted one color out of 7
// "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
//ROYGBIV
void paint(List *head,int n)
{
	List* p = head->next;
	
	int i = 0;
	while (p != head->next||i==0) {
		while (1) {
			int j = i % 7;
			if (p->prior->val != color[j] && p->prior->prior->val != color[j] && p->prior->prior->prior->val != color[j])
			{
				if (p->next->val != color[j] && p->next->next->val != color[j] && p->next->next->next->val != color[j])
				{
					p->val = color[j]; break;
				}
			}
			i++;
		}
		p = p->next;
	}
		
	
}


int main()
{
	int n; cin >> n;
	List* head = Creat(n);
	paint(head, n);
	List* p = head->next;
	int i = 0;
	while (p != head->next||i==0) {
		cout << p->val;
		p = p->next;
		++i;
	}
	//向前找三个后找三个
	//没有能放下的就返回上一个?//不用吧


	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值