A - Apple Pie
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100points
Problem Statement
We have AA apples and PP pieces of apple.
We can cut an apple into three pieces of apple, and make one apple pie by simmering two pieces of apple in a pan.
Find the maximum number of apple pies we can make with what we have now.
Constraints
- All values in input are integers.
- 0 \leq A, P \leq 1000≤A,P≤100
Input
Input is given from Standard Input in the following format:
A P
Output
Print the maximum number of apple pies we can make with what we have.
Sample Input 1
1 3
Sample Output 1
3
We can first make one apple pie by simmering two of the three pieces of apple. Then, we can make two more by simmering the remaining piece and three more pieces obtained by cutting the whole apple.
Sample Input 2
0 1
Sample Output 2
0
We cannot make an apple pie in this case, unfortunately.
Sample Input 3
32 21
Sample Output 3
58
#include<iostream>
using namespace std;
int main()
{
int a,p,sum;
scanf("%d%d",&a,&p);
sum=(a*3+p)/2;
printf("%d\n",sum);
return 0;
}
B - Guidebook
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
Problem Statement
You have decided to write a book introducing good restaurants. There are NN restaurants that you want to introduce: Restaurant 11, Restaurant 22, ......, Restaurant NN. Restaurant ii is in city S_iSi, and your assessment score of that restaurant on a 100100-point scale is P_iPi. No two restaurants have the same score.
You want to introduce the restaurants in the following order:
- The restaurants are arranged in lexicographical order of the names of their cities.
- If there are multiple restaurants in the same city, they are arranged in descending order of score.
Print the identification numbers of the restaurants in the order they are introduced in the book.
Constraints
- 1 ≤ N ≤ 1001≤N≤100
- SS is a string of length between 11 and 1010 (inclusive) consisting of lowercase English letters.
- 0 ≤ P_i ≤ 1000≤Pi≤100
- P_iPi is an integer.
- P_i ≠ P_jPi=Pj (1 ≤ i < j ≤ N)(1≤i<j≤N)
Input
Input is given from Standard Input in the following format:
NN S_1S1 P_1P1 :: S_NSN P_NPN
Output
Print NN lines. The ii-th line (1 ≤ i ≤ N1≤i≤N) should contain the identification number of the restaurant that is introduced ii-th in the book.
Sample Input 1 Copy
6 khabarovsk 20 moscow 10 kazan 50 kazan 35 moscow 60 khabarovsk 40
Sample Output 1 Copy
3 4 6 1 5 2
The lexicographical order of the names of the three cities is kazan
<< khabarovsk
<< moscow
. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,23,4,6,1,5,2.
Sample Input 2 Copy
10 yakutsk 10 yakutsk 20 yakutsk 30 yakutsk 40 yakutsk 50 yakutsk 60 yakutsk 70 yakutsk 80 yakutsk 90 yakutsk 100
Sample Output 2 Copy
10 9 8 7 6 5 4 3 2 1
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int n;
struct node{
string name;
int score,ff;
}a[102];
bool cmp(node b,node c)
{
if(b.name==c.name) return b.score>c.score;
return b.name<c.name;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
cin>>a[i].name>>a[i].score;
a[i].ff=i+1;
}
sort(a,a+n,cmp);
for(int i=0;i<n;i++) printf("%d\n",a[i].ff);
return 0;
}
C - Switches Editorial
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300300 points
Problem Statement
We have NN switches with "on" and "off" state, and MM bulbs. The switches are numbered 11 to NN, and the bulbs are numbered 11 to MM.
Bulb ii is connected to k_iki switches: Switch s_{i1}si1, s_{i2}si2, ......, and s_{ik_i}siki. It is lighted when the number of switches that are "on" among these switches is congruent to p_ipi modulo 22.
How many combinations of "on" and "off" states of the switches light all the bulbs?
Constraints
- 1 \leq N, M \leq 101≤N,M≤10
- 1 \leq k_i \leq N1≤ki≤N
- 1 \leq s_{ij} \leq N1≤sij≤N
- s_{ia} \neq s_{ib} (a \neq b)sia=sib(a=b)
- p_ipi is 00 or 11.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
NN MM k_1k1 s_{11}s11 s_{12}s12 ...... s_{1k_1}s1k1 :: k_MkM s_{M1}sM1 s_{M2}sM2 ...... s_{Mk_M}sMkM p_1p1 p_2p2 ...... p_MpM
Output
Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.
Sample Input 1 Copy
2 2 2 1 2 1 2 0 1
Sample Output 1 Copy
1
- Bulb 11 is lighted when there is an even number of switches that are "on" among the following: Switch 11 and 22.
- Bulb 22 is lighted when there is an odd number of switches that are "on" among the following: Switch 22.
There are four possible combinations of states of (Switch 11, Switch 22): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 11.