Permuting Two Arrays




   

Consider two -element arrays of integers,  and . You want to permute them into some  and  such that the relation  holds for all  where . For example, if , and , a valid  satisfying our relation would be  and .

You are given  queries consisting of , and . For each query, print YES on a new line if some permutations  exist satisfying the relation above. If no valid permutations exist, print NO instead.

Input Format

The first line contains an integer, , denoting the number of queries. The  subsequent lines describe each of the queries in the following format:

  1. The first line contains two space-separated integers describing the respective values of  (the size of arrays and ) and  (the relation variable).
  2. The second line contains  space-separated integers describing the respective elements of array .
  3. The third line contains  space-separated integers describing the respective elements of array .

Constraints

Output Format

For each query, print YES on a new line if valid permutations exist; otherwise, print NO.

Sample Input

2
3 10
2 1 3
7 8 9
4 5
1 2 2 1
3 3 3 4

Sample Output

YES
NO

Explanation

We perform the following two queries:

  1. , and . We permute these into  and  so that the following statements are true:

    Thus, we print YES on a new line.

  2. , and . To permute  and  into a valid  and , we would need at least three numbers in  to be greater than ; as this is not the case, we print NO on a new line.





JSONObject obj = new JSONObject();

obj.put("id", result.getId());

obj.put("theme", result.getTheme());

obj.put("title", result.getTitle());

obj.put("address", result.getAddress());

obj.put("memo", result.getMemo());

obj.put("imgpath", result.getImgpath());


{"address":"서울 종로구 우정국로2길 21",

 "imgpath":"d:\\mapstarImg\\testId_20171229075929343.jpg",

 "memo":"눈치안보임",

 "theme":"스터디까페",

 "id":"testId",

 "title":"마이크임팩트스퀘어"}


이런식으로 {"키:벨류", "키":"벨류"} 로 담깁니다. 


JSONArray arr = new JSONArray();

arr.add(obj); 


[{"address":"서울 종로구 우정국로2길 21",

 "imgpath":"d:\\mapstarImg\\testId_20171229075929343.jpg",

 "memo":"눈치안보임",

 "theme":"스터디까페",

 "id":"testId",

 "title":"마이크임팩트스퀘어"}]


담아논 JSONObject를 JSONArray 안에 넣어줍니다. 

[ {"키:벨류", "키":"벨류"} ]  

//Ajax JSON response

response.setContentType("text/html; charset=utf-8"); 

PrintWriter writer = response.getWriter();

writer.print(arr.toString());

writer.flush();

writer.close()


response로 보냅니다.


Ajax에서 받아 JSON.parse해서 받습니다.
entry.키 값으로 벨류를 가져와서 각자 활용 합니다.

success: function (datas) {
var dataResult = JSON.parse(datas);
$.each(dataResult, function(index, entry) {
alert("entry::"+entry.id);
alert("entry::"+entry.title);
alert("entry::"+entry.address);
alert("entry::"+entry.theme);
alert("entry::"+entry.memo);
alert("entry::"+entry.imgpath);
});
},




TIL-2017/12/30(토)


오늘의 이야기

- 단어113 강의1.-(1,2/5) 독서2-6,7,8,9

  꾸준함의 힘을 믿는다. 제법 여유가 있게 진행되는 것 같다. 눈앞에 성과에 연연하지 말고 자투리 시간을 활용하여 꾸준히 가자.

- mapstar coding 

  JSONArray, JSONObject, Ajax, JSON.parse 를 처리하고 포스팅 하였다. 먼가 어색하고 잘 정리되는지 모르겠지만 하다보면 나아질거라 본다. 

  img path parsing해서 갤러리 만듬, 타이틀 공백 처리 

  

TIL-2018/1/9(화)


오늘의 이야기 > 8:10 

- 단어113누적, 강의1-(3/5), 기억전략 암기의힘 몰입 

  연초에 일이 많아 쉬는 기간이 길었다. 그치만 다시 돌아왔다!! 계속 가자~

- 템플릿 수정하여 등록 페이지 1차 완성  

  작은 부분들이 남아 있지만 1차 완성은 하였다. 체크사항 두고 다음페이지 작업 할것. 

- 알고리즘 : Permuting Two Arrays 

  알고리즘 프로젝트에 멤버가 충원되면서 새롭게 시작되었다. 포스팅도 다시!! 

- 네트워크 공부 시작 

  "성공과 실패를 결정하는 1%의 네트워크" 책으로 공부를 시작하였다. 브라우저에 URL을 입력하고 홈페이지가 표시되기 까지의 과정을

   아주 상세하고 흐름에 맞추어 설명한다. 구조를 잡아가면서 잘 정리해 갈것. 재밌다.  


TIL-2018/1/9(화)


오늘의 이야기 > 8:55 

- 단어126, 강의1, 2(1),목표

  꾸준히 잘 되는 부분. 만족스럽다. 양+질의 시간을 보내도록 유념할것 

- listView페이지 템플릿 1차완성

  이 페이지도 세부사항 정리해서 등록 페이지와 함께 마무리 해야겠다. 그리고 하면서 사용하는 script나 java 그냥 쓰고 넘기지 말고 잘 익혀둘것

- 알고리즘 : 배열 좌우 동일한 합 구하기 

  뭔가 신통방통한 풀이가 아니여서 조금 부족하단 생각이 든다. 다른사람 풀이도 참고해서 최적의 풀이를 찾아보자

- 문자열 계산기를 통한 테스트와 리펙토링

  완공에서 배운 적절한 과제 수행 수준 같다. 적당히 어려워서 흥미가 생기고 집중이 잘된다. 리펙토링 부분은 해당 코드로 꾸준히 복습해서 알고리즘

  코드에도 적용 해 볼것

- 네트워크

  초입이지만 상당히 세세하게 설명하고 있기 때문에 반복해서 봐야할 것 같다. 웹이 어떻게 돌아가는지 내 주특기가 되기를!!

- 데이터베이스

  "하루30분 SQL첫걸음"이란 책을 보기 시작 했는데 초입이라 쉬워서 3강까지 보았다. 아는 내용이 많이 나오지만 이번기회에 확실히 정리해 둘것


: 만족스러웠지만 여전히 양+질의 공부를 하고 있는지 매 시간 체크하면서 가야할 것 같다. 지금처럼 많이 공부할 수 있는 시간이 없을 거니까 잘 활용하자.



Not allowed to load local resource


브라우저에서는 사용자 로컬에 접근할 수 없음


  • 이클립스에서 JSP로 개발시 파일경로 설정방법 (http://blog.itthis.me/28) 

<img src="${pageContext.request.contextPath}/resources/img/profile.jpg">

<img src="/resources/img/profile.jpg">

http://localhost:8082/resources/img/profile.jpg

비교 http://localhost:8082/mapstar/insert

  •  resources mapping

  • <Context docBase="d:\test_img" path="/local_img" reloadable="true"></Context>    > 시스템 경로 사용 시 

  • java의 File에서 파일을 읽기/쓰기 할때는 제일 쉬운방법은 절대경로(웹경로 x)를 넣는 것이고,

html등의 웹페이지에서 이미지 출력시에는 context의  상대경로/절대경로를 넣어야 합니다.

그리고, 이미지의 경우, WEB-INF 하위로 두게 되면 일반 웹URL로 인식안되니

ROOT 하위로 빼놓으셔야 합니다  > 프로젝트 안으로 

(https://okky.kr/article/317040?note=1043455)

  • Web Browser를 통해서 이미지를 보고자 할때에는

Http 서비스가 가능한 위치여야 합니다. 

일반적으로 Http Server에서 이미지파일이나 스크립트, 또는 css 등의 파일에 접근하기 위해서는

해당 경로가 Http URL로 지정이 되어 있어야 하는거죠...

예로 Tomcat에서 개발을 한경우 Context 로 지정된 폴더및 그 하위의 모든 폴더 들은

Http URL로 접근이 가능하게 됩니다. 

님처럼 특정 폴더에 파일을 올리시고 그것을 Web을 통해서 서비스를 하시려면..

Servlet 단에서 response 로 파일을 보내시면 됩니다. > 아예 파일로 response

해당 예제들은 구글에서 검색하시면 쉽게 찾을수 있을 거예요..

(https://okky.kr/article/417238)

  • 접금권한 자체가 웹 루트부터 시작 하니까요.
    위 글처럼 하시려면직접 파일을 읽어서 스트림으로 내려주면 됩니다.

  (https://okky.kr/article/237812)

TIL_171223

오늘 한 것

  웹프로그래밍 Next Step 
          테스트와 리팩토링 ing  
  mapstar coding 
          파일 업로드 form ajax 처리 
  완벽한 공부법 독서 
         3장 기억. 단기기억, 장기기억 
  단어, 강의 
         챕터3-2 완료 


+ Recent posts