## Googudong's Adventure

Googu Dong is a playful child. One day, he got a magical circle from an ancient relic.This ring consists of an alphabet that connects the beginning and the end of the ring. It has a pointer that initially points to the letter A.Gugudong can rotate one square clockwise or counterclockwise at a time.For example, a rotates clockwise to z and counterclockwise to b.Googu Dong has a string in his hand, but he is too dumb, so he comes to ask you for help and asks how many times he needs to go at least.

Input

The input has only one line and is a string.

Output

Output the minimum number of times to rotate.

Sample input

zeus

Sample output

18

Solving problems

Check-in question, for each subtitle look to determine whether the clockwise or counterclockwise turn is closer, add up

#include<iostream> #include<cmath> #include<algorithm> #include <cstring> #include <string> #include <cstdio> using namespace std; #define ll long long string s; ll ans = 0; int cal(char x,char y) { int numx = x - 'a'; int numy = y - 'a'; if(numx > numy) { int t = numx; numx = numy; numy = t; } if((numy-numx) >= 0 && (numy-numx) < (numx+26-numy)) { return (numy-numx); } else return (numx+26-numy); } int main() { cin>>s; char c = 'a'; for(int i=0;i<s.length();i++) { ans += cal(c,s[i]); c = s[i]; } cout<<ans; return 0; }

## Googu Dong wants to eat

The Googudong exam week starts, with a total of n days on Monday.He didn't want to be so tired during the exam week, so he planned to have a good meal every day.He decided to eat raw fry every day, and Gu Gudong needed to buy ai raw fry every day.However, in order to stimulate consumption, there are only two ways of purchase: 1. Buy two fries at a time on a certain day.(2) Buy a raw fry today and a raw fry for tomorrow at the same time. The shop will give you a ticket and use it the next day to get it.There are no other ways to buy. These two ways can be used countless times, but Gugudong is a frugal kid. He left after training, and he is not allowed to have vouchers in his hand at the end of training.Googudong is very rich. You don't need to worry about Googudong not having money. But Googudong is too dumb. He asks you if you can buy ai raw fry every day during the exam week.

Input

Enter two lines, the first with a positive integer n (1<=n<=100000) representing the number of days in the test week.

The second line has n numbers, and the ith number AI (0<=ai<=10000) indicates the number of raw fries to be bought on day i I.

Output

Output "YES" if it can meet the odd requirements of Goudong, and output "NO" if it cannot.(Output without quotation marks)

Sample input1

4

1 2 1 2

Sample output1

YES

Sample input2

3

1 0 1

Sample output2

NO

Solving problems

At that time, when I was doing this question, my thoughts were out of line. I looked at the range of N and thought I had to go through it day by day to record the answers. Later, I found that it was very troublesome, n *ai's enumeration is obviously unacceptable, and then it comes to mind that the score ai is even and odd, but since you ran too long in the wrong way and didn't get it back in the end, this is really not an AC problem.

The solution is an uncomplicated greed. If you want to buy an even number today, if you want to buy an odd number and have no vouchers in your hand, add one to the number of vouchers. Otherwise, use one voucher.It's illegal to buy zero vouchers one day or in the end

#include<iostream> #include<cmath> #include<algorithm> #include <cstring> #include <string> #include <cstdio> #include <queue> using namespace std; #define ll long long int n,x,tickets; bool flag; int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>x; if(x%2) { if(tickets == 0) { tickets++; } else { tickets--; } } else { if(x==0) { if(tickets) { flag = true; break; } } } } if(tickets%2||flag) { cout<<"NO"; } else { cout<<"YES"; } return 0; }

## Terrible cosmic rays

Cosmic rays penetrate the human heart

As we all know, Raytheon has reached the ceiling of CS undergraduate, but we do not know that there are days outside and people outside are meticulous.In the vast universe, there is a kind of creature called Goodness, which is naturally capable of reaching the level of knowledge of human postgraduates and is naturally good at CSP, even the first level in the country!But the scariest thing is that it can emit cosmic rays!Cosmic rays can destroy a person's intelligence quotient and smart blow!

Cosmic rays propagate on an infinite two-dimensional plane (as a two-dimensional grid), with the initial direction up by default.Cosmic rays will split after a distance has been emitted, splitting two cosmic rays at 45 degrees to the left and right of that direction with the same power!Cosmic rays split n times, each time ai1 units in length in the direction of the split.

Now Reishan is going to challenge the dog with his younger brothers, but Reishan doesn't want to bring his IQ down to the level of normal undergraduate zjm food, so Reishan asks you to help him figure out how many locations will be "smart hit"

Input

The first input line contains a positive integer n, (n<=30), indicating that the cosmic rays will split n times.

The second line contains n positive integers a1,a2,..., an, and the I I number ai(ai < 5) indicating how many units of length the first splitting cosmic ray will continue i n its original direction.

Output

Output a number ans to indicate how many positions will be hit by a drop in intelligence.

Sample input

4

4 2 2 3

Sample output

39

Solving problems

It was seen during the competition that the correct solution was to be derived from a combination of mathematics, but the process was not clear, and I was casually masked and scored no points.Having spent a long time after the game Other people's blogs And learn about solutions.

This graph is a symmetric process that keeps going outwards. Because the more it splits back, the more it bifurcates, we go forward from the last symmetric backtrace and add all the points to the set because the set internal elements are ordered and automatically weighted, so it is easy to record the answers, and the final output size is the answer.

#include<iostream> #include<cmath> #include<algorithm> #include <cstring> #include <string> #include <cstdio> #include <queue> #include <set> using namespace std; #define ll long long struct node { int x,y; bool operator < (const node& b)const { return x != b.x ? x < b.x : y < b.y; } }; set<node>mmap; int v[51],n; int qx[] = {0,1,1,1,0,-1,-1,-1}; int qy[] = {1,1,0,-1,-1,-1,0,1}; void dfs(node p,int cnt,int direct) { if(cnt > n)return; dfs({p.x + qx[direct] * v[cnt], p.y + qy[direct] * v[cnt]},cnt + 1,(direct + 1)%8);//Divide Backward set<node>temp;//Record the point to which this split extends forward for(auto& i : mmap) { if(direct == 0 || direct == 4) { temp.insert({p.x * 2 - i.x,i.y}); } else if(direct == 2 || direct == 6) { temp.insert({i.x,p.y * 2 - i.y}); } else if(direct == 1 || direct == 5) { temp.insert({i.y + p.x - p.y,i.x + p.y - p.x}); } else if(direct == 3 || direct == 7) { temp.insert({p.x + p.y - i.y,p.x + p.y - i.x}); } } mmap.insert(temp.begin(),temp.end()); for(int i = 1; i<= v[cnt]; i++) { mmap.insert({p.x + qx[direct] * i,p.y + qy[direct] * i}); } } int main() { cin>>n; for(int i = 1;i <= n;i++) { cin>>v[i]; } dfs({0,0},1,0); cout<<mmap.size(); return 0; }