Wow! Such String !, Wowsuchstring

Source: Internet
Author: User

Wow! Such String !, Wowsuchstring

Question Link

  • Question:
    To n, output a string with the length of n so that the string can be connected to any of the four characters without repeating N (1 ≤ N ≤ 500000)
  • Analysis:
Const int MAXV = 18278; const int MAXE = 475228; struct Edge {int from, to;}; struct Direct_Euler {int n, m; int out [MAXV]; bool vis [MAXE]; vector <int> G [MAXV]; vector <Edge> edges; stack <int> sk; vector <int> ans; void init (int n) {this-> n = n; edges. clear (); REP (I, n) {out [I] = 0; G [I]. clear () ;}} void addEdge (int a, int B) {edges. push_back (Edge) {a, B}); m = edges. size (); G [a]. push_back (m-1); Out [a] ++; out [B] --;} void dfs (int u, int ind) {REP (I, G [u]. size () {int x = G [u] [I]; Edge & e = edges [x]; if (! Vis [x]) {vis [x] = true; dfs (e. to, x) ;}} if (ind> = 0) sk. push (ind);} // returns 1: Euler's loop returns 2: Euler's path through int solve (int s) {int cnt = 0; ans. clear (); REP (I, n) {if (out [I] = 1) {if (++ cnt> 1) {return 0 ;}s = I ;} else if (out [I]> 1 | out [I] <-1) return 0;} while (! Sk. empty () sk. pop (); REP (I, m) vis [I] = false; dfs (s,-1); REP (I, m) if (! Vis [I]) return 0; while (! Sk. empty () {ans. push_back (sk. top (); sk. pop ();} return cnt! = 0? 1: 2 ;}} graph; char x [456979], tot = 0; int main () {int size = 29 <20; // 29 MB char * p = (char *) malloc (size) + size; _ asm _ ("movl % 0, % esp \ n ":: "r" (p); graph. init (18278); REP (I, 26) REP (j, 26) REP (k, 26) REP (l, 26) graph. addEdge (I * 676 + j * 26 + k, j * 676 + k * 26 + l); graph. solve (0); vector <int> & ans = graph. ans; int tot = 0; int to = graph. edges [ans [0]. from; x [tot ++] = to/676 + 'a '; To % = 676; x [tot ++] = to/26 + 'a'; to % = 26; x [tot ++] = to + 'a '; REP (I, ans. size () x [tot ++] = graph. edges [ans [I]. to % 26 + 'a'; int n; while (~ RI (n) {if (n> tot) puts ("Impossible"); else {REP (I, n) printf ("% c", x [I]); puts ("") ;}} return 0 ;}


In fact, if you didn't think it was the Euler's loop problem, you can try it again. I regret that I didn't write it at the time and pay homage to it ..
const int MAXN = 1000000;bool vis[26][26][26][26];int x[MAXN];int tot;int main(){    tot = 0;    REP(i, 26)    {        x[tot + 3] = x[tot + 2] = x[tot + 1] = x[tot] = i;        tot += 4;    }    FF(i, 3, tot)        vis[x[i]][x[i - 1]][x[i - 2]][x[i - 3]] = 1;    bool flag = true;    while (flag)    {        flag = false;        REP(i, 26)        {            if (!vis[i][x[tot - 1]][x[tot - 2]][x[tot - 3]])            {                vis[i][x[tot - 1]][x[tot - 2]][x[tot - 3]] = 1;                x[tot++] = i;                flag = true;            }        }    }    int n;    while (~RI(n))    {        if (n > tot)            puts("Impossible");        else        {            REP(i, n)                printf("%c", x[i] + 'a');            puts("");        }    }    return 0;}



Differences and usage of so and such

1. so + adjectives/adverbs + that + clauses, such:
This story is so interesting that I want to read it again. (This story is so interesting that I want to read it again .)
He spoke so quickly that I couldn't follow him.
(He spoke so quickly that I couldn't keep up with him .)
2. so + adjective/adverbs + (a/an) + (singular) Plural count noun/unmeasurable noun + that + clause. If a noun in a sentence is a singular count noun, we need to use an uncertain title a or an. If there are only a few or unmeasurable nouns in the plural, we don't need a title in front of it, for example:
She is so lovely a girl that everyone loves he (this story is so interesting that I want to read it again .) R.
(She is such a cute girl that everyone loves her .)
Those are so beautiful flowers that the girl wants to pick them. (Those flowers are so beautiful that the girl wants to pick them up .)
3. such + a/an + adjective + Singular count noun + that + clause, for example:
She is such a lovely girl that everyone loves her. (She is such a cute girl that everyone loves her .)
It is such an interesting story that I want to read it again. (This is such an interesting story that I want to read again .)
4. such + Plural count noun/unmeasurable noun + that + clause, for example:
He showed such concern that people took him to be a relative. (He is so concerned that people treat him as a relative .)
Reference: zhidao.baidu.com/..&rn=10

String type, explaining the cause of the result

I want to print the results. You should know what it is.
The reason is as follows:
F knows that the result is "qq" during compilation, so it shares the same String object with.
E is not a constant during compilation, so it will point to a new String object.

The original article is as follows: please read it with patience
The compiler optimizes handling of string literals (and compile-time constant
Expressions that evaluate to strings): only one String object is shared by all string valued
Constant expressions with the same character sequence. Such strings are
Said to be interned, meaning that they share a unique String object if they have
Same content. The String class maintains a private pool where such strings are
Interned.
String str2 = "You cannot change me! ";
Both String references str1 and str2 denote the same String object, initialized
The character string: "You cannot change me! ". So does the reference str3 in the following
Code. The compile-time evaluation of the constant expression involving
Two string literals, results in a string that is already interned:
String str3 = "You cannot" + "change me! "; // Compile-time constant expression
In the following code, both the references can1 and can2 denote the same String
Object that contains the string "7Up ":
String can1 = 7 + "Up"; // Value of compile-time constant expression: "7Up"
String can2 = "7Up"; // "7Up"
However, in the code below, the reference can4 will denote a new String object that
Will have the value "7Up" at runtime:
String word = "Up ";
String can4 = 7 + wor ...... remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.