SlideShare a Scribd company logo
1 of 5
Download to read offline
Zig Zag Nametag
BOJ 11230
2020-12-05
김봄
SAMPLE INPUT/OUTPUT
1
19
77
ab
at
aoazb
1 − 2 = 1
1 − 20 = 19
1 − 15 + 15 − 1 + 1 − 26 + 26 − 2
= 14 + 14 + 25 + 24
= 77
SOLUTION
• 모든 문자열은 AZAZAZAZ…와 같은 구조를 가지고 두 번째 문자와 마지막 문자만 변경한다.
• 두 번째 문자는 b부터 z까지 가능하다.
• 마지막 문자는 a, b, y, z만 가능하다.
CODE
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int k;
int solution(string s) {
int sum = 0;
for (int i = 1; i < s.length(); i++) {
sum += abs(s[i]-s[i-1]);
}
return sum;
}
int main() {
cin >> k;
int len = ceil(k / 25.0) + 1;
string s;
for (int i = 0; i < len; i++) {
s += (i % 2 == 0) ? 'a' : 'z';
}
string clist = "abyz";
for (char second = 'b'; second <= 'z'; second++) {
for (char last:clist) {
string tmp = s;
tmp.back() = last;
tmp[1] = second;
if (solution(tmp) == k) {
cout << tmp << endl;
return 0;
}
}
}
}
EXPLANATION
• 당연하게도 대부분의 문자열은 azazaz 와 같이 25씩 더해야 한다.
• 다르게 더할 수 있는 부분이 있다면 처음과 끝이다.
• 처음 두 문자와 마지막 두 문자가 바뀔 수 있다.
• 처음 두 문자의 절댓값 차이가 뭐가 나오던 둘 중 하나는 a가 가능하고
사전 순으로 앞선 문자열을 출력해야 하니 맨 앞 문자는 무조건 a이다.
• 두 번째 문자에 의해 마지막 문자가 결정된다. (경우에 따라 불가능할 수 있다)
• 두 번째 문자가 변경되면 전체 sum은 2씩 변경된다. 𝑎𝑎 − 𝑏𝑏 + 𝑏𝑏 − 𝑐𝑐
• 두 번째 문자가 모든 것을 결정하고 마지막 문자는 2씩 변경되는 문제를 해결하기 위해 하나씩 감소하거나 증가하면 된다.
• 마지막 문자는 a, b, y, z만 가능하다.

More Related Content

Recently uploaded

Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)
Wonjun Hwang
 

Recently uploaded (7)

A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)
 
도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'
도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'
도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'
 
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
 
Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차
 
[Terra] Terra Money: Stability and Adoption
[Terra] Terra Money: Stability and Adoption[Terra] Terra Money: Stability and Adoption
[Terra] Terra Money: Stability and Adoption
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

BOJ11230

  • 1. Zig Zag Nametag BOJ 11230 2020-12-05 김봄
  • 2. SAMPLE INPUT/OUTPUT 1 19 77 ab at aoazb 1 − 2 = 1 1 − 20 = 19 1 − 15 + 15 − 1 + 1 − 26 + 26 − 2 = 14 + 14 + 25 + 24 = 77
  • 3. SOLUTION • 모든 문자열은 AZAZAZAZ…와 같은 구조를 가지고 두 번째 문자와 마지막 문자만 변경한다. • 두 번째 문자는 b부터 z까지 가능하다. • 마지막 문자는 a, b, y, z만 가능하다.
  • 4. CODE #include<iostream> #include<string> #include<cmath> using namespace std; int k; int solution(string s) { int sum = 0; for (int i = 1; i < s.length(); i++) { sum += abs(s[i]-s[i-1]); } return sum; } int main() { cin >> k; int len = ceil(k / 25.0) + 1; string s; for (int i = 0; i < len; i++) { s += (i % 2 == 0) ? 'a' : 'z'; } string clist = "abyz"; for (char second = 'b'; second <= 'z'; second++) { for (char last:clist) { string tmp = s; tmp.back() = last; tmp[1] = second; if (solution(tmp) == k) { cout << tmp << endl; return 0; } } } }
  • 5. EXPLANATION • 당연하게도 대부분의 문자열은 azazaz 와 같이 25씩 더해야 한다. • 다르게 더할 수 있는 부분이 있다면 처음과 끝이다. • 처음 두 문자와 마지막 두 문자가 바뀔 수 있다. • 처음 두 문자의 절댓값 차이가 뭐가 나오던 둘 중 하나는 a가 가능하고 사전 순으로 앞선 문자열을 출력해야 하니 맨 앞 문자는 무조건 a이다. • 두 번째 문자에 의해 마지막 문자가 결정된다. (경우에 따라 불가능할 수 있다) • 두 번째 문자가 변경되면 전체 sum은 2씩 변경된다. 𝑎𝑎 − 𝑏𝑏 + 𝑏𝑏 − 𝑐𝑐 • 두 번째 문자가 모든 것을 결정하고 마지막 문자는 2씩 변경되는 문제를 해결하기 위해 하나씩 감소하거나 증가하면 된다. • 마지막 문자는 a, b, y, z만 가능하다.