For the vijos11.2 simulation Competition

Source: Internet
Author: User

I made a special title, but I just wanted to remind myself not to make fun of it in the future (so there should be no gods to come in ?)

 

When I wrote T1 and T3 on the spot, I felt that they could not be written. After reading the question, I still felt that they could not be written. At this time, I am too lazy to take care of such difficult things.

Mark T2 and T4.

 

I seldom write strings recently. T2 is a lesson;

Getchar () when reading line breaks ();

Getline (S, CIN) is used to read the entire line (with spaces) string );

Getchar () is not required when reading the next row.

By the way, review...

However, there is a very pitfall in this question, that is, there is space behind the number t, and there is more than one Qaq

Therefore, after reading T, You Need To while (C = getchar () = '');

Details get √

Attach your silly program:

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <string>using namespace std;int T;char c;string s;int a[10],ans;int main(){//freopen("data.txt","r",stdin);scanf("%d",&T);    while((c=getchar())==‘ ‘);for(int k=1;k<=T;k++){memset(a,0,sizeof(a));getline(cin,s);int l=s.size();for(int i=0;i<l;i++){if(s[i]==‘ ‘) a[1]++;if(s[i]==‘g‘) a[2]++;if(s[i]==‘o‘) a[3]++;if(s[i]==‘d‘) a[4]++;if(s[i]==‘m‘) a[5]++;if(s[i]==‘r‘) a[6]++;if(s[i]==‘n‘) a[7]++;if(s[i]==‘i‘) a[8]++;}a[2]/=2;a[3]/=3;a[7]/=2;sort(a+1,a+9);ans=a[1];printf("Case #%d: %d\n",k,ans);}return 0;}

 

 

T4: Brute Force + Search rules;

I was so stupid to understand the wrong question and got down with brute force attacks.

By the way, I just mentioned where I got my mistake.

The first is especially silly. I cannot understand what a 64-bit unsigned integer is. (unsigned long is not used for several hundred years. I don't even know how to fight)

Then I don't know much about bitwise operations. When I was violent, I went to DFS (x + 1 ,(~ Sum) ^ A [x + 1]) can be written, and I am also drunk = sum (~ Sum )?!...

After that, I was particularly amused by the input, for I = 1 ~ N cout <A [I]; (I am stupid =)

Mom, if it's so funny, noip will be Qaq

 

In fact, I will only fight for violence, but I don't know how to use it.

After reading the problem, I realized that it was a brute force + Regular searching!

When Random n = 8, it is found that the minimum value is 0 ,. That is to say, in the case where the brute force is correct, n = 8 has already been able to get 0, so when n> 8, you must choose to connect all the following numbers, the answer is still 0;

Therefore, for N> 7, we can directly obtain the answer 0, n <= 7, and solve it with brute force;

 

MARK:

1. When unsigned long is output, besides cout, % i64u can also be used.

2. Min value minx. Do not assign values randomly! Because unsigned long is very large! In case of chaos, it may be smaller than the minimum value! Therefore, it should be assigned a [1].

Be careful with this!

 

Attach your silly program:

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;int T;int n;unsigned long long a[101],minx;void search(int x,unsigned long long  sum){if(x==n){if(sum<minx) minx=sum;return;}else{search(x+1,sum^a[x+1]);search(x+1,sum|a[x+1]);search(x+1,sum&a[x+1]);search(x+1,sum^(~a[x+1]));search(x+1,sum|(~a[x+1]));search(x+1,sum&(~a[x+1]));}}int main(){//freopen("data.txt","r",stdin);scanf("%d",&T);for(int k=1;k<=T;k++){memset(a,0,sizeof(a));scanf("%d",&n);if(n>7){for(int i=1;i<=n;i++) cin>>a[i];printf("Case #%d: %d\n",k,0);}else{         for(int i=1;i<=n;i++) cin>>a[i];     minx=a[1];     search(1,a[1]);     search(1,(~a[1]));     printf("Case #%d: %I64u\n",k,minx);}   }return 0;}

 

For the vijos11.2 simulation Competition

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.