import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
class Solution {
	public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int T;
		T=Integer.parseInt(sc.nextLine());
	
		StringBuffer sb = new StringBuffer();
		StringTokenizer st;
		for(int test_case = 1; test_case <= T; test_case++)
		{
			
			st= new StringTokenizer(sc.nextLine()," ");
			
			int N = Integer.parseInt(st.nextToken());
			String X = st.nextToken();
			
			int temp=0;
			for(int i=0;i<X.length();i++) {
				temp += Character.getNumericValue(X.charAt(i));
			}
			
			int result = temp % (N-1);
			
			sb.append("#"+test_case+" "+result).append('\n');
			 
		}
		System.out.print(sb);
	}
}

 

모듈로 연산,, 미쳤go ,,

자릿수 더해준 것과 같은 결과 ,,,,**

 

'NOTE > SWEA' 카테고리의 다른 글

7985. Rooted Binary Tree 재구성 - d3  (0) 2022.06.15
8556. 북북서  (0) 2022.06.15
10993. 군주제와 공화제 - d3  (0) 2022.06.15
12051. 프리셀 통계 - d3  (0) 2022.06.12
13732. 정사각형 판정 - d3  (0) 2022.06.12
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;
class Solution {
	static int[] arr;
	static int[] result;
	static int len;
	static ArrayList<Integer> al;
	public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int T;
		T=Integer.parseInt(sc.nextLine());
	
		StringBuffer sb = new StringBuffer();
		StringTokenizer st;
		for(int test_case = 1; test_case <= T; test_case++)
		{
			int K = Integer.parseInt(sc.nextLine());
			st= new StringTokenizer(sc.nextLine()," ");
			arr = new int[st.countTokens()];
			result = new int[st.countTokens()];
			len = arr.length;
			int i=0;
			while(st.hasMoreTokens()) {
				arr[i]=Integer.parseInt(st.nextToken());
				i++;
			}
			
			restructure(0,arr.length,1);
		
			sb.append("#"+test_case+" ");	   
            
            int cnt=1;
            int index=0;
            for(int j=0; j<K ; j++) {
                for(int z=0; z<cnt; z++) {
                	sb.append(result[index]+" ");
                	index++;
                }
                cnt*=2;
                sb.append("\n");
            } 
		}
		System.out.print(sb);
	}
	
	static void restructure(int start, int end, int num) {
		if(isInterval(start)|| isInterval(end)|| isInterval(num)) return;
		
		int mid = (start+end)/2;
		
		result[num-1]=arr[mid];
	
		System.out.println(num-1);
		
		if(start==end) return;

		restructure(start,mid-1, 2*num);
		restructure(mid+1,end,2*num+1);
	}
	
	static boolean isInterval(int n) {
		return (n>len || n<0);
	}
}
 

큰일이다 내 머리놈 거부 시작하네;;

이해하는데 한참 생각했다 ㅎ

 

가운데, 왼쪽 가운데, 오른쪽 가운데 ~

이를 위해 왼쪽  2*num 오른쪽이 하나 더 큰 2*num+1

 

그러니깐,,

num-1, 2*num-1, 2*num ..  이 순서로 가운데, 왼쪽 가운데, 오른쪽 가운데 ..

 

 

 

+ 그리고 이거 쓸때마다 까먹음 ;; ㅎ ㅎ

 

* boolean hasMoreTokens() - 토큰이 더 이상 있는지 여부를 알아본다.

* countTokens() - 토큰의 개수를 리턴한다.

 

'NOTE > SWEA' 카테고리의 다른 글

7193. 승현이의 수학공부 - d3  (0) 2022.06.16
8556. 북북서  (0) 2022.06.15
10993. 군주제와 공화제 - d3  (0) 2022.06.15
12051. 프리셀 통계 - d3  (0) 2022.06.12
13732. 정사각형 판정 - d3  (0) 2022.06.12
import java.util.ArrayList;
import java.util.Scanner;

class Solution {

	public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int T;
		T=Integer.parseInt(sc.nextLine());
	
		StringBuffer sb = new StringBuffer();
		
		for(int test_case = 1; test_case <= T; test_case++)
		{
			String s = sc.nextLine();
			ArrayList<Integer> al = new ArrayList<>();
			
			if(s.endsWith("north")) {
				s=s.substring(0,s.length()-5);
				al.add(0);
			}else{
				s=s.substring(0,s.length()-4);
				al.add(90);
			}
		
			int count=1;
			int sum =0;
			
			while(!s.equals("")) {
				if(s.endsWith("north")) {
					s=s.substring(0,s.length()-5);
					al.add(-90);
				}else{
					s=s.substring(0,s.length()-4);
					al.add(90);
				}
				count*=2;
			}
			
			String result = "";

			for(int i=0; i<al.size(); i++) {
				sum += al.get(i)*(Math.pow(2,al.size()-1-i));
			}
			
			while(sum%2==0 && count!=1) {
				sum/=2;
				count/=2;
			}
			
			if(count==1) {
				result = Integer.toString(sum);
			}else {
				result = Integer.toString(sum)+"/"+Integer.toString(count);
			}
			
			sb.append("#"+test_case+" "+result).append('\n');

		}
		System.out.print(sb);
	}
}

 

 

이거는 다시 복습해야겠다 .. 

 

for(int i=0; i<al.size(); i++) {
	sum += al.get(i)*(Math.pow(2,al.size()-1-i));
}

 

이 부분,, 생각 못했다 ^^

으앙 똥 멍충이냐구요 ~

'NOTE > SWEA' 카테고리의 다른 글

7193. 승현이의 수학공부 - d3  (0) 2022.06.16
7985. Rooted Binary Tree 재구성 - d3  (0) 2022.06.15
10993. 군주제와 공화제 - d3  (0) 2022.06.15
12051. 프리셀 통계 - d3  (0) 2022.06.12
13732. 정사각형 판정 - d3  (0) 2022.06.12
import java.util.StringTokenizer;
import java.util.Scanner;

class Solution {
	static StringTokenizer st;
	static String[] result; 
	static Country[] countries;
	public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int T;
		T=Integer.parseInt(sc.nextLine());
	
		StringBuffer sb = new StringBuffer();
		
		for(int test_case = 1; test_case <= T; test_case++)
		{
			int N = Integer.parseInt(sc.nextLine());
			countries = new Country[N+1];
			for(int i=1; i<=N; i++) {
				st = new StringTokenizer(sc.nextLine()," ");
				int X = Integer.parseInt(st.nextToken());
				int Y = Integer.parseInt(st.nextToken());
				double S = Double.parseDouble(st.nextToken());
				countries[i]=new Country(X,Y,S);
			}
			
			result = new String[N+1];
			for(int i=1; i<=N; i++) {
				double maxThreat =0; 
				for(int j=1; j<=N; j++) {
					if(i==j)continue;
					double threat = threat(countries[j],countries[i]);
					if(threat>countries[i].s) {
						if(threat>maxThreat) {
							maxThreat = threat;
							countries[i].control=j;
						}else if(threat==maxThreat) {
							countries[i].control=-1;
						}
					}
				}
			}
			
			sb.append("#"+test_case+" ");
			
			String result ="";
			for(int i=1; i<=N; i++) {
				result+= getResult(i)+" ";
			}
			sb.append(result+'\n');
		}
		System.out.print(sb);
	}
	static double threat(Country i, Country j) {
		return i.s/(Math.pow((j.x-i.x),2)+Math.pow((j.y-i.y),2)); 
	}
	
	static String getResult(int i) {
		if(countries[i].control==-1) { //여러개
			return "D";
		}else if(countries[i].control==0) {
			return "K";
		}else{
			return Integer.toString(getAncestor(i));
		}
	}
	
	static int getAncestor(int i) {
	    if(countries[i].control == -1 || countries[i].control== 0) {
	         return i;
	    }else {
	         return getAncestor(countries[i].control);
	    }
	}
}

class Country{
	int x;
	int y;
	double s; //군사력
	int control=0;
	public Country(int x, int y, double s) {
		this.x = x;
		this.y = y;
		this.s = s;
	}
}

 

자꾸 테케  일부만 맞아가지고

화만 가득이다가 풀이 봤다..

(근데 난,,문제 안풀리면 웰케 화가 날까 ,,,? ㅋ ㅎ ㅋ ㅎ 🤯😂)

내가 못 풀 문제였던 것 같다. 잘 안풀어본 문제..

 

문제의 부분은 정답 출력과 getAncestor 부분..

만약 3을 5가 지배했다면 3이 지배했던 나라들도 5가 지배하는 걸로 바뀌게 되는데

이 부분 구현을 잘못했다.

 

i를 누가 지배를 하고 있다면, i를 지배한 나라의 지배한 나라를 확인 ........ 이런 식으로 타고타고,,

그래서 ancestor..

이렇게 푸는 방식을 전혀 생각하지 못한 부분이었다.😭

 

'NOTE > SWEA' 카테고리의 다른 글

7985. Rooted Binary Tree 재구성 - d3  (0) 2022.06.15
8556. 북북서  (0) 2022.06.15
12051. 프리셀 통계 - d3  (0) 2022.06.12
13732. 정사각형 판정 - d3  (0) 2022.06.12
13038. 교환학생 - d3  (0) 2022.06.11
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Solution {
	public static void main(String[] args) throws IOException{
      // TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int T;
		T=Integer.parseInt(br.readLine());
		
		StringBuffer sb = new StringBuffer();
		StringTokenizer st;
		for(int test_case = 1; test_case <= T; test_case++)
		{
			st = new StringTokenizer(br.readLine()," ");
			long N = Long.parseLong(st.nextToken());
			int pD = Integer.parseInt(st.nextToken());
			int pG = Integer.parseInt(st.nextToken());

			boolean check = true;
			
			if((pG==100 && pD!=100)|| (pG==0 && pD !=0) || isInteger(N,pD)==false ) {
				check =false;
			}
			String result = (check == true) ? "Possible" : "Broken";

			sb.append("#"+test_case+" "+result).append('\n');
		}
		System.out.print(sb);
	}
	static boolean isInteger(Long N, int pD) {
		for(Long i=N; i>=1; i--) {
			if((i*pD)%100 ==0) return true;
		}
		return false;
	}
}

 

제출 제일 많이 했던 문제 같다 .. ㅋ ㅋ ..

제출만 하면 런타임 에러 떠서 화 가득이었다🤯

이왜안..?

 

결국 활동점수 깎고 다른 사람 풀이를 봤는데

내 문제였다 마자 컴퓨터는 잘못없지 ..

 

N의 범위는 1 ≤ N ≤ 10^15

 

이걸 Long으로 안받아서 ............... 반성하자..^^

 

그리고 정수인지 확인하는 부분에서 % 활용하는거 생각 못했다..  앞으로 활용해야지 🔥

'NOTE > SWEA' 카테고리의 다른 글

8556. 북북서  (0) 2022.06.15
10993. 군주제와 공화제 - d3  (0) 2022.06.15
13732. 정사각형 판정 - d3  (0) 2022.06.12
13038. 교환학생 - d3  (0) 2022.06.11
10761. 신뢰 - d3  (0) 2022.06.11
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
static int N;
static String[] arr;
	public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
		int T;
		T=Integer.parseInt(br.readLine());
      
		StringBuilder sb = new StringBuilder();
		for(int test_case = 1; test_case <= T; test_case++)
		{ 
			N = Integer.parseInt(br.readLine()); 
			arr = new String[N];
    	  
			for(int i=0; i<N; i++) {
				arr[i] = br.readLine();
			}
			
			int starti=N-1;
			int startj= N-1; 
			int endi =0;
			int endj =0;
			
			for(int i=0; i<N; i++) {
				if(!arr[i].contains("#")) continue;
				for(int j=0; j<N; j++) {
					if(arr[i].charAt(j) == '#') {
						starti=Math.min(starti,i);
						startj=Math.min(startj,j);
						endi=Math.max(endi,i);
						endj=Math.max(endj,j);
					}
				}
			}
			boolean check = true;
            for(int i = starti; i <= endi; i++) {
                for(int j = startj; j <= endj; j++) {
                    if(arr[i].charAt(j)=='.') {
                    	check=false;
                    	break;
                    }
                }
            }
            String result = (check && endi-starti == endj-startj) ? "yes":"no";
			sb.append("#"+test_case+" "+result).append('\n');
		}
		System.out.print(sb);
	}
}

 

20개 test case 중에 16개만 맞아서

내가 생각하지 못한 예외가 뭘까 하구 ,, 하다가

시간이 너무 지체되서 😂🤣😂🤯😭

사람들 풀이를 보았다 ,,^^

 

내가 너무 복잡하게 생각했구나 느꼈고 

endi-starti 랑 endj-startj 같은지 검사하는 거에서 소름(?) 😱

이걸 왜 생각못했을까 했다. ....

가로 세로 길이 같은 지 검사해서 정사각형 판단할수도 있는데 ~~~ 

왜 난 생각 못했냐구요 ~

 

'NOTE > SWEA' 카테고리의 다른 글

10993. 군주제와 공화제 - d3  (0) 2022.06.15
12051. 프리셀 통계 - d3  (0) 2022.06.12
13038. 교환학생 - d3  (0) 2022.06.11
10761. 신뢰 - d3  (0) 2022.06.11
7227. 사랑의 카운슬러 - d3  (0) 2022.06.11
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
	static int N;
	static String s;
	static int[] days;
	static int answer;
    public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
      int T;
      T=Integer.parseInt(br.readLine());
      
      StringBuilder sb = new StringBuilder();
      StringTokenizer st;
      for(int test_case = 1; test_case <= T; test_case++)
      { 
    	  N = Integer.parseInt(br.readLine()); //n일동안 수업 들음
    	  days = new int[7];    	 
    	  
    	  st = new StringTokenizer(br.readLine()," ");
    	  
    	  for(int i=0; i<7;i++) {
    		  days[i]=Integer.parseInt(st.nextToken());
    	  }
    	  
    	  answer = Integer.MAX_VALUE;
    	  
    	  for(int i=0; i<7; i++) {
    		  if(days[i]==1) {
		       	 answer=Math.min(answer,takeLesson(i));
    		 }
    	 }
   
    	 sb.append("#"+test_case+" "+answer).append('\n');
      }
      System.out.print(sb);
   }

    static int takeLesson(int i) {
    	int count = 0;
     	  int result = 0;
     	  while(count!=N) {
     		  if(days[i%7]==1) {
     			 count++;
     		  }
     		  result++;
     		  i++;  
     	  }
     	 return result;
    }
}

 

처음에 문제 이해를 잘못했었다.

댓글 보고 문제를 이해했다..

 

요일을 어디서부터 시작해야하는거지 싶었는데

처음에 1이 시작하는 부분부터 해서 틀룠다..

 

어디로 시작해도 상관없고 다만 최소여야 한다는거 !

 

0 1 0 0 0 1 1

이게 days에 들어가 있고 N이 2라면

 

답은 2가되어야 한다.

(일월화수목금토)

금,토 수강하면 되니깐 🤩

 

'NOTE > SWEA' 카테고리의 다른 글

12051. 프리셀 통계 - d3  (0) 2022.06.12
13732. 정사각형 판정 - d3  (0) 2022.06.12
10761. 신뢰 - d3  (0) 2022.06.11
7227. 사랑의 카운슬러 - d3  (0) 2022.06.11
9778. 카드 게임 - d3  (0) 2022.06.10
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Solution {
	static int time;
	static int locationB;
	static int locationO;
	static ArrayList<Integer> B;
	static ArrayList<Integer> O;
    public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      
      int T;
      T=Integer.parseInt(br.readLine());
      
      StringBuilder sb = new StringBuilder();
      StringTokenizer st;
      
      for(int test_case = 1; test_case <= T; test_case++)
      {
    	  st = new StringTokenizer(br.readLine()," ");
    	  int N = Integer.parseInt(st.nextToken());
    	  String[] sequenceRobot = new String[N];
    	  B = new ArrayList<>();
    	  O = new ArrayList<>();
    	  
    	  for(int i=0; i<N; i++) {
    		   sequenceRobot[i]=st.nextToken();
    		   if(sequenceRobot[i].equals("B")) {
    			   B.add(Integer.parseInt(st.nextToken()));
    		   }else {
    			   O.add(Integer.parseInt(st.nextToken()));
    		   }
    	  }
    	  
    	 time = 0;
    	 locationB = 1;
    	 locationO = 1;
    	 int i=0;
    	 while(B.size()!=0 || O.size()!=0) {
    		 if(B.size()!=0 && O.size()==0) {
    			 while(B.size()!=0) {
    				 delete(B.get(0),"B");
    			 }
    		 }else if(O.size()!=0 && B.size()==0) {
    			 while(O.size()!=0) {
    				 delete(O.get(0),"O");
    			 }    			 
    		 }else {
    			 String robot = sequenceRobot[i];
    			 i++;
    			 int buttonB = B.get(0);
    			 int buttonO = O.get(0);
    			 
    			 int moveB = Math.abs(locationB-buttonB);
    			 int moveO = Math.abs(locationO-buttonO);
    			 
    			 if (robot.equals("B")) {
    				 delete(buttonB,"B");
                     if (moveB>=moveO) {//O가 움직인 시간동안 갈 수 있음
                         locationO = buttonO;
                     } else{ //가까운쪽으로 움직이기
                         if (locationO > buttonO) 
                        	 locationO -= (moveB + 1);
                         else if (locationO < buttonO) 
                        	 locationO += (moveB + 1);
                     }
                 }else{
                	 delete(buttonO,"O");
                	 if (moveO>=moveB) { //B가 움직인 시간동안 갈 수 있음
                         locationB = buttonB;
                     } else{
                         if (locationB > buttonB) 
                        	 locationB -= (moveO + 1);
                         else if (locationB < buttonB) 
                        	 locationB += (moveO + 1);
                     }
                 }
    			 
    		 }
    		 
    	 }
    	  sb.append("#"+test_case+" "+time).append('\n');
      }
      System.out.print(sb);
   }
    
    static void delete(int button,String s) {
		if(s.equals("B")) {
			time += (Math.abs(locationB-button)+ 1);
       	 	locationB = button;
       	 	B.remove(0);
		}
		else {
			time += (Math.abs(locationO-button)+ 1);
       	 	locationO = button;
       	 	O.remove(0);
		}
    }
}

처음에 문제 이해부터 헤맸다

그리고 테케 5개만 맞았다해서 당황했다..^^

그냥 다 틀린거잖아요~..

 

그래서 여러 풀이들을 보고.......

나는 B랑 O랑 ArrayList 따로 만들어서 푸는 것을 택했다....

'NOTE > SWEA' 카테고리의 다른 글

13732. 정사각형 판정 - d3  (0) 2022.06.12
13038. 교환학생 - d3  (0) 2022.06.11
7227. 사랑의 카운슬러 - d3  (0) 2022.06.11
9778. 카드 게임 - d3  (0) 2022.06.10
7102. 준홍이의 카드놀이 - d3  (0) 2022.06.10

+ Recent posts