1. 程式人生 > >ACM-ICPC 2018 焦作賽區網絡預賽

ACM-ICPC 2018 焦作賽區網絡預賽

span art -s tro for each 4 sum set blank 所有

A-Magic Mirror

Jessie has a magic mirror.

Every morning she will ask the mirror: ‘Mirror mirror tell me, who is the most beautiful girl in the world?‘ If the mirror says her name, she will praise the mirror: ‘Good guy!‘, but if the mirror says the name of another person, she will assail the mirror: ‘Dare you say that again?‘

Today Jessie asks the mirror the same question above, and you are given a series of mirror‘s answers. For each answer, please output Jessie‘s response. You can assume that the uppercase or lowercase letters appearing anywhere in the name will have no influence on the answer. For example, ‘Jessie‘ and ‘jessie‘ represent the same person.

Input

The first line contains an integer T(1T100), which is the number of test cases.

Each test case contains one line with a single-word name, which contains only English letters. The length of each name is no more than 15.

Output

For each test case, output one line containing the answer.

樣例輸入

2
Jessie
Justin

樣例輸出

Good guy!
Dare you say that again?
解題思路:簽道題,把源字符串中的所有大寫字母改成小寫字母,然後再判斷即可。
AC代碼:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 string str;int t;
 4 int main(){
 5     while(cin>>t){
 6         while(t--){
 7             cin>>str;
 8             for(int i=0;str[i];++i)
 9                 if(isupper(str[i]))str[i]+=32;
10             if(str=="jessie")cout<<"Good guy!"<<endl;
11             else cout<<"Dare you say that again?"<<endl;
12         }
13     }
14     return 0;
15 }

G-Give Candies

There are N children in kindergarten. Miss Li bought them N candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N), and each time a child is invited, Miss Li randomly gives him some candies (at least one). The process goes on until there is no candy. Miss Li wants to know how many possible different distribution results are there.

Input

The first line contains an integer T, the number of test case.

The next T lines, each contains an integer N.

1 ≤ T ≤ 100

1 N 10^100000

Output

For each test case output the number of possible results (mod 1000000007).

樣例輸入

1
4

樣例輸出

8
解題思路:簽道題,這道題跟hdu4704一樣,題解鏈接:題解報告:hdu 4704 Sum(整數快速冪+費馬小定理)。此題題意為給任意多個小夥伴分糖果,每個人可以得到0﹣n塊糖果,求將n分完的方案數。很容易想到隔板法,有n-1個空,每個空可以選擇插入或不插入一塊隔板,那麽一共有2^(n-1)種方案數,由於n很大且取模大質數,因此要用費馬小定理來降冪。
AC代碼:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=1000000007;
 5 const int maxn=1e5+5;//N最大有10^5位
 6 char str[maxn];int t;
 7 LL mod_power(LL a,LL b){//整數快速冪
 8     LL ans=1;
 9     while(b){
10         if(b&1)ans=ans*a%mod;
11         a=a*a%mod;
12         b>>=1;
13     }
14     return ans;
15 }
16 int main(){
17     while(cin>>t){
18         while(t--){
19             cin>>str;
20             LL N=0;
21             for(int i=0;str[i]!=\0;++i)
22                 N=(10*N+(str[i]-0))%(mod-1);//先處理指數N%(p-1)
23             cout<<mod_power(2,N-1)<<endl;//再求2^(N-1)%mod
24         }
25     }
26     return 0;
27 }

I-Save the Room

Bob is a sorcerer. He lives in a cuboid room which has a length of A, a width of B and a height of C, so we represent it as A * B * C. One day, he finds that his room is filled with unknown dark energy. Bob wants to neutralize all the dark energy in his room with his light magic. He can summon a 1 * 1 * 2 cuboid at a time to neutralize dark energy. But the cuboid must be totally in dark energy to take effect. Can you foresee whether Bob can save his room or not?

Input

For each line, there are three integers A, B, C.

1 A, B, C 100

Output

For each test case, if Bob can save his room, print"Yes", otherwise print"No".

樣例輸入

1 1 2
1 1 4
1 1 1

樣例輸出

Yes
Yes
No
解題思路:簽道題,很容易就發現如果a*b*c為偶數,則為"Yes",否則為"No"。
AC代碼:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main(){
 4     int a,b,c;
 5     while(cin>>a>>b>>c){
 6         if(a*b*c&1)cout<<"No"<<endl;
 7         else cout<<"Yes"<<endl;
 8     }
 9     return 0;
10 }

K-Transport Ship

There are N different kinds of transport ships on the port. The i_th kind of ship can carry the weight of V[i] and the number of the i_th kind of ship is 2^C[i]?1. How many different schemes there are if you want to use these ships to transport cargo with a total weight of S?

It is required that each ship must be full-filled. Two schemes are considered to be the same if they use the same kinds of ships and the same number for each kind.

Input

The first line contains an integer T(1T20), which is the number of test cases.

For each test case:

The first line contains two integers: N(1N20),Q(1Q10000), representing the number of kinds of ships and the number of queries.

For the next N lines, each line contains two integers: V[i](1V[i]20),C[i](1C[i]20), representing the weight the i_th kind of ship can carry, and the number of the i_th kind of ship is 2^C[i]?1.

For the next Q lines, each line contains a single integer: S(1S10000), representing the queried weight.

Output

For each query, output one line containing a single integer which represents the number of schemes for arranging ships. Since the answer may be very large, output the answer modulo 1000000007.

樣例輸入

1
1 2
2 1
1
2

樣例輸出

0
1
解題思路:本來是一道簽道題,由於比賽時把數量看成編號,導致一直WA(搞砸了),QAQ=_=||。題意:給定N種船,每種船有2^C[i]-1艘,每種船能承載V[i]的貨物,有q個詢問,問選擇若幹艘船裝滿重量為S的方案總數。顯然這是一道多重背包裸題,二進制將其轉化成01背包即可。dp[j]表示用若幹艘船裝成重量為j的方案數,相關思想,看這裏:題解報告:hdu 1284 錢幣兌換問題(簡單數學orDP)
AC代碼:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const LL mod=1e9+7;
 5 int t,n,q,cnt,x,y,num,c[22],val[500],s;LL dp[10005];
 6 int main(){
 7     for(int i=0;i<21;++i)c[i]=(1<<i)-1;
 8     while(~scanf("%d",&t)){
 9         while(t--){
10             memset(dp,0,sizeof(dp));dp[0]=1;cnt=0;
11             scanf("%d%d",&n,&q);
12             for(int i=1;i<=n;++i){
13                 scanf("%d%d",&x,&y),num=c[y];
14                 for(int d=1;d<=num;num-=d,d<<=1)
15                     val[cnt++]=x*d;
16                 if(num>0)val[cnt++]=x*num;
17             }
18             for(int i=0;i<cnt;++i){
19                 for(int j=10000;j>=val[i];--j)
20                     dp[j]=(dp[j]+dp[j-val[i]])%mod;
21             }
22             while(q--){
23                 scanf("%d",&s);
24                 printf("%lld\n",dp[s]);
25             }
26         }
27     }
28     return 0;
29 }

ACM-ICPC 2018 焦作賽區網絡預賽