zoukankan      html  css  js  c++  java
  • Ducci Sequence UVA

    习惯用结构体包一个数组,要存进set/map的话需要重载一下小于号,这样就能判重了

    #include<bits/stdc++.h>
    #include<stdio.h>
    #include<algorithm>
    #include<queue>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    using namespace std;
    #define ll long long
    const int maxn=1e2+7;
    const int inf=0x3f3f3f3f;
    #define FOR(n) for(int i=1;i<=n;i++)
    #define pb push_back
    
    /******************************************************/
    namespace fastIO{  
    	#define BUF_SIZE 100000  
    	#define OUT_SIZE 100000  
    	#define ll long long  
    	//fread->read  
    	bool IOerror=0;  
    	inline char nc(){  
    		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;  
    		if (p1==pend){  
    			p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);  
    		if (pend==p1){IOerror=1;return -1;}  
    		//{printf("IO error!
    ");system("pause");for (;;);exit(0);}  
    	}  
    	return *p1++;  
    }  
    inline bool blank(char ch){return ch==' '||ch=='
    '||ch=='
    '||ch=='	';}  
    inline void read(int &x){  
    	bool sign=0; char ch=nc(); x=0;  
    	for (;blank(ch);ch=nc());  
    	if (IOerror)return;  
    	if (ch=='-')sign=1,ch=nc();  
    	for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';  
    	if (sign)x=-x;  
    }  
    inline void read(ll &x){  
    	bool sign=0; char ch=nc(); x=0;  
    	for (;blank(ch);ch=nc());  
    	if (IOerror)return;  
    	if (ch=='-')sign=1,ch=nc();  
    	for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';  
    	if (sign)x=-x;  
    }  
    inline void read(double &x){  
    	bool sign=0; char ch=nc(); x=0;  
    	for (;blank(ch);ch=nc());  
    	if (IOerror)return;  
    	if (ch=='-')sign=1,ch=nc();  
    	for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';  
    	if (ch=='.'){  
    		double tmp=1; ch=nc();  
    		for (;ch>='0'&&ch<='9';ch=nc())tmp/=10.0,x+=tmp*(ch-'0');  
    	}  
    	if (sign)x=-x;  
    }  
    inline void read(char *s){  
    	char ch=nc();  
    	for (;blank(ch);ch=nc());  
    	if (IOerror)return;  
    	for (;!blank(ch)&&!IOerror;ch=nc())*s++=ch;  
    	*s=0;  
    }  
    inline void read(char &c){  
    	for (c=nc();blank(c);c=nc());  
    	if (IOerror){c=-1;return;}  
    } 
    #undef OUT_SIZE  
    #undef BUF_SIZE  
    }; using namespace fastIO;
    /*****************************************************/
    
    struct NODE{
    	int n;
    	int arr[16];
    	bool operator <(const NODE &b)const{
    		for(int i=1;i<=n;i++){
    			if(arr[i]!=b.arr[i])return arr[i]<b.arr[i];
    		}
    		return 0;
    	}
    };
    
    //set<NODE>S;
    map<NODE,bool>vis;
    
    int main(){
    	int T;
    	//scanf("%d",&T);
    	read(T);
    	while(T--){
    		vis.clear();
    		NODE st;
    		//scanf("%d",&st.n);
    		read(st.n);
    		for(int i=1;i<=st.n;i++){
    			//scanf("%d",&st.arr[i]);
    			read(st.arr[i]);
    		}
    
    		vis[st]=1;
    
    		for(int p=1;p<=1111;p++){
    			int tmp=st.arr[1];
    			int flag=1;
    			for(int i=1;i<st.n;i++){
    				st.arr[i]=abs(st.arr[i+1]-st.arr[i]);
    				if(st.arr[i]!=0)flag=0;
    			}
    			st.arr[st.n]=abs(st.arr[st.n]-tmp);
    			if(st.arr[st.n]!=0)flag=0;
    
    			if(flag){
    				printf("ZERO
    ");
    				break;
    			}
    			else if(!vis[st]){
    				//S.insert(st);
    				vis[st]=1;
    			}else if(vis[st]){
    				printf("LOOP
    ");
    				break;
    			}
    		}
    
    	}
    }


  • 相关阅读:
    根据痛点分析制作软件
    大学生三大痛点及分析
    统计作业
    蜜迹(个人项目设计)
    一款有趣的影子游戏《Shadowmatic-投影寻真》
    Java项目实战_疫情地图可视化_day03
    Java项目实战_疫情地图可视化_day02
    Java项目实战_疫情地图可视化_day01
    《敏捷软件开发原则,模式与实践》阅读笔记三
    《敏捷软件开发原则,模式与实践》阅读笔记二
  • 原文地址:https://www.cnblogs.com/Drenight/p/8611258.html
Copyright © 2011-2022 走看看