These two questions can be put together. 1231 is an evolutionary version of 1003...
I used the same method for these two questions: O (1) space complexity O (n) time complexity... this is my own statement and I am wrong.
In fact, if you open an array in 1231, it will be about the same as when you write 1003. Of course, you 'd better not open it.
Touch me 1st touch me 2nd
1003 of the Code was written earlier...
1 #include <iostream> 2 using namespace std; 3 4 const int inf = 0x3f3f3f3f; 5 int main() 6 { 7 int t , n , i , j; 8 bool flag; 9 int num , sum , mmax , st , end;10 while( ~scanf("%d",&t) )11 {12 flag = false;13 for( int k = 1 ; k<=t ; k++ )14 {15 sum = 0;16 scanf( "%d",&n );17 mmax = -inf;18 j = 1;19 for( int i = 1 ; i<=n ; i++ )20 {21 scanf( "%d",&num );22 sum += num;23 if( sum>mmax )24 {25 mmax = sum;26 st = j;27 end = i;28 }29 if( sum<0 )30 {31 sum = 0;32 j = i + 1;33 }34 }35 printf( "Case %d:\n%d %d %d\n%s",k,mmax,st,end,k>=t?"":"\n" ); 36 }37 }38 return 0;39 }
View code
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 cin.sync_with_stdio(false); 7 int n , sum , max , st , end , temp , a, b , num; 8 while( cin >> n && n ) 9 {10 sum = 0;11 max = -1;12 for( int i = 0 ; i<n ; i++ )13 {14 cin >> num;15 if( i==0 )16 a = num;17 else if( i==n-1 )18 b = num;19 sum += num;20 if( sum>=0 && sum-num<=0 )21 {22 temp = num;23 }24 if( sum>max )25 {26 max = sum;27 st = temp;28 end = num;29 }30 if( sum<0 )31 {32 sum = 0;33 }34 }35 if( max == -1 )36 {37 cout << 0 << " " << a << " " << b << endl; 38 }39 else40 {41 cout << max << " " << st << " " << end << endl;42 }43 }44 return 0;45 }
View code
The most important thing about 1231 is that the initial value of Max is-1, and this solution must be-1. At first, it took a detour with 0.
Today:
We recommend an article from <mint>
At that time, I liked her feeling. How can I say it. She was sitting in the classroom, not conspicuous at all. She often sat in the fourth position in the fifth row, and the first three were her roommates. Before class, they talk together, broken, like a small white rice grain on the mud. When it was her turn to speak, the shortest dimples in her mouth were exposed, with a small sound, and people who spoke and looked at the conversation with their eyes, her eyes will be a little erratic, and there will still be slight smile marks on her lips; in class, linguistics, ancient literature, modern literature, drama and drama research, no matter what course, she copied the teacher's speech in her notebook with a single word, but she never raised her hand to answer questions. When the other called classmates answered, she put the gel pen on her notebook side and scanned her eyes out of the window. Her hair burst by a fan on the ceiling, pick up the pen to take notes.
I love to answer questions. When my teacher asks a question, I raise my hand. Later, the students developed a habit. As long as the teacher asks a question, they will turn to me. I was a little embarrassed because I was worried that I would be so fond of showing the limelight. In an ancient literature class, the teacher asked Meng Haoran what poems he had written in Xiangyang. I knew the answer when a book was rummaging in the classroom, but I couldn't lift my hand on the desk. At this time, the classroom was in an embarrassing silence. The teacher got used to raising his hand. Suddenly, he was a little embarrassed. Some of you stabbed me with a pen: "Let's take a look! Only you can answer this question ." I looked down and looked at my notes, and I felt a lot in my heart. I wanted to answer a few questions: why can't they answer them? "Tong Ling, please answer ." The teacher gave me a name from the roster. I looked up and saw that she was slightly stunned. Her roommate pushed her up and said, "Yes, you are !" She stood up in a hurry and held a gel pen in her hand. "Well, this, uh ......" The other hand gathered his hair frequently and his face was dizzy. Seeing this, I immediately raised my hand. The teacher seemed to have been rescued and said to Tong Ling, "well, sit down first. You can answer this question ." Tong Ling gave me a look and sat down.
When I was studying at night, I sat behind and watched novels borrowed from the library. She and her roommates were far away reading English Class 4 questions in the front row. She wore a thin blue coat and a new pink-green card with her ears. When I was tired, I went for a walk on the runway outside the teaching building. Our university is in the valley. The moon stops on the mountain beam behind the teaching building, and the wind blows to the treasure of pine forests. When a person is walking outside, it is a little cool. Looking up at the thin clouds in the sky, her voice came over: "What are you watching ?" I turned and looked at her and stood behind me. I pointed to the sky and looked at it: "how nice the clouds look ." She smiled at me and looked at the sky again: "Well, it looks nice ." When I had no words, I asked, "Are you going back to the dormitory ?" She said, "No. I plan to buy a notebook at the supermarket. Do you want to accompany me ?"
In the old campus, supermarkets go along the foot of the hill, and the insects on the hills are ringing, the couples on the opposite side of the road are laughing, and the jingles of bicycles riding around, it sounds around us. She walked in my right hand side without a sound, and I could not find anything. "Thank you ." She suddenly looked up and said. I shook my hand and said, "Nothing. I have to take a walk ." She smiled and said, "I am not talking about this. I am talking about answering questions in the last lesson ." I said, "What is that? It is a very simple problem ." She paused: "Yes, I don't know ." I found myself wrong. I was busy explaining: "Don't get me wrong. I didn't mean that ." She smiled and shook her shoulders this time. "You are too serious ." When I saw her not angry, I put my mind down. She is shorter than me, probably on my shoulder. As soon as she bowed her head, I could see her thin neck exposed under the lights of the street lamp, and then let people feel pity, she was very eager to stretch her hand into her own arms. I was so confused by these chaotic ideas that I could not hear her questions clearly. "I mean, how do you know so many writers ?" She repeated her questions again and again. "I think you are amazing. The teachers are praising you for a wide range of knowledge ." I felt like my face was burning.
I keep thinking about her while lying in bed. After the lights are turned off, my roommates will talk about it for a while as usual. Speaking of the girls in the class, they will always look around those pretty girls. No one mentioned Tong Ling. Perhaps in the eyes of roommates, Tong Ling is neither beautiful nor distinctive, and can be ignored completely. This gives me peace of mind. No one talks about her any good, and of course no one talks about her any bad. She is faint among many girls, like a wisp of mint. Only I can capture it. At the same time, I feel that the feeling of pity is getting stronger and stronger. I 'd like to know more about her. But how can I ask other people? I often touched her on the road. She had passed the CET4 test and had to take the computer Level 2 test again. She and her roommates took hands to go to the computer training class of the off-campus finance school. I smiled and nodded, I also nodded with a smile and had no chance to say a word again. She is not going to study at night in the classroom. She must be doing exercises in the computer room. I read a book in the classroom, and then look at the location where she often sat. Other girls are already sitting.
Students planning to take a Postgraduate Entrance Exam rented a house in a village near the school and invited me to eat dumplings together. When I bought some fruit, the house was full of people in our class who planned to take a postgraduate entrance exam. I saw her at first glance. She wants to take an postgraduate entrance exam. I know that the major is Linguistics. The university to be applied for is a famous university and it is difficult to take an exam. Her English level 6 has passed, and her computer Level 2 has passed. She thought clearly from college. Unlike me, I don't want to take these creden。, I just want to read the books in random. At that moment, I suddenly regretted it: If I applied for these training classes like her, maybe I could spend a little more time with her. Everyone carried the table to the yard, and the noodles, the noodles, and dumplings.
It was really difficult to pack dumplings. I made a few fillings and all of them were revealed. on her side, the dumplings were fully packed and put on the lid. She suddenly came together, and her face was very close to me. I was so scared that she was hiding. She did not notice that she looked at the dumplings in her hand and said, "You have a wrong bag. I will teach you ." I put my eyes together with her face in the light of my eyes, and I could smell her face. If there was no fragrance in her body, her little nose was covered with flour. I almost needed to raise my hand to help her erase it, but no. My heartbeat was so bad that I was worried that she could hear it, and then let it go. "Okay, that's it. Have you learned ?" Her face suddenly fell away, her eyes looked at me, I nodded, she smiled again, continue to pack her dumplings. Although I have taught it again, I still cannot. She picked up a dumpling skin and asked me to look at it again. She cleverly picked up the dumpling skin with her fingers and painted pink nail polish on her fingernails. I learned that she had wrapped one. It really looked like a thing. She nodded, "you're still pretty smart ." I smiled and replied, "the teacher will teach me ."
The dumplings are boiled in a pot. Waiting is also waiting. Everyone is sitting in the yard and chatting. The autumn sun shines on your head and is warm. On the tree in the back of the house, a few birds are not stopping. The mountains of yucolored mountains are filled with rich white clouds. Sitting in the middle of a group of female students, she blinks her eyes and listens to others. Her mouth is slightly tilted, with a slight smile. I probably felt that I was watching her. She smiled at me and went to the speaker again. My heart burst and I don't know whether her smile has any special meaning. The speaker suddenly asked her, "What happened to your boyfriend at the normal university? Didn't you go to him ?" She frowned and said, "I cannot tell you clearly. He always said that he would help me contact the teacher ." The speaker nodded and said, "We 'd better borrow all the teaching materials and notes from the normal university ." I couldn't quite hear how she responded later. Once the dumplings are ripe, everyone picks up the bowl and eats them. I slowly eat dumplings in the bowl, very hot mouth, can only chew a little bit. She sat down at the door and picked up her mouth to blow hot noodle soup. Her face was in the hot air and she couldn't see her face for a while.
She did not attend any courses in her senior year's first half. She was dedicated to preparing for the exam in the Postgraduate classroom. Sometimes she can meet her in the dining room. She takes the enamel bowl while cooking and reads the English vocabulary dictionary for postgraduate entrance exams. I walked behind her silently and did not dare to disturb her. Every time you fetch water, you can see her open water bottle put out of the open water room. The bottle body is written with a modified liquid with the first letter of her name pinyin: "TL ". I think many times, maybe I should be glad that I didn't express anything to her, so we will not be embarrassed. She hovered like the air in my heart, and it won't make me feel bad, but it's just a little stunned. After the postgraduate entrance exam, dormitory roommates finally mentioned Tong Ling for the first time. That was also said by their roommates: "Tong Ling's first test has not passed ." In this case, we did not stop talking a few more words, but talked about other students who have not passed the examination. I am lying in bed and suddenly want to get up immediately to find her, or call her, but I know this is futile. What can I tell her?
One day after the postgraduate entrance exam, we will soon have to graduate from college. We are busy looking for a job, while the people who have taken the postgraduate entrance exam are busy preparing for the retest. But I didn't see Tong Ling at every job fair on campus, and she disappeared. When she met her roommate, she asked casually and replied that she had gone to her boyfriend's school. Maybe I will never see her again. It arrived in February. One week before graduation, the class organized to go to the off-campus restaurant for a meal. At that time, I had already found an advertisement copywriting job in an advertising company. After work in the evening, everyone had to eat it. I have never eaten any food, and everyone is scrambling for toast. After drinking, I have not said a few words, and all of them are crying. As soon as I thought of these students, I could not help but burst into tears. When I looked at my classmates on other tables, I saw Tong Ling sitting in the middle of my roommate. Her hair was long and she wore her shoulder and her face became thin and sharp. She leaned her head on her roommate's shoulder. Her face was red and her tears slipped from her face, and she was not able to wipe her hands, letting her slide to her chin. My heart suddenly experienced a violent sensation of pain. Soon some people came to hold me and say something special about each other. I tried my best to look at her.
After drinking the wine, we walked in and sang loudly on campus, without any teacher interfering with us. The stars in the sky are like boiling, and drill straight into my eyes. I vomited several times and walked on the road again. There is a scent of trees in the wind, and I breathe. Send the female students to the female dormitory. We do not hold on to each other as we used to, and the male and female students embrace each other. I picked up many female students and cried again. She looked up at me when she hugged Tong Ling and looked up. She looked up and looked up at me with a smile. I held her in my arms and hugged her thin shoulder. Her body is hot and cheesy. She patted her shoulder and said, "Remember to contact me often ." I said, "well ." I loose my hand and asked, "Are you looking for a job ?" She smiled and said, "I'm going to take another year ." I nodded, "You can do it ." She said "thank you ". What else do I want to say? Her eyes have moved to the next boy and she hugged each other. She also said, "Remember to contact me in the future ." His hand patted him on his shoulder.
-------------