apple pie
We have �A apples and �P 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.
#include<iostream>
#include <istream>
#include<algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <stack>
#include <sstream>
#include <stdlib.h>
#include <iomanip>
#include <utility>
//#define int long long
using namespace std;
//priority_queue <int> q;
//int mgcd(int x, int y)
//{
// if (y == 0) return x;
// return mgcd(y, x % y);
//}
int main()
{
int x, y;
cin >> x >> y;
int ans = (x * 3 + y) / 2;
cout << ans;
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 �N restaurants that you want to introduce: Restaurant 11, Restaurant 22, ......, Restaurant �N. Restaurant �i is in city ��Si, and your assessment score of that restaurant on a 100100-point scale is ��Pi. 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
#include<iostream>
#include <istream>
#include<algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <stack>
#include <sstream>
#include <stdlib.h>
#include <iomanip>
#include <utility>
//#define int long long
using namespace std;
//priority_queue <int> q;
//int mgcd(int x, int y)
//{
//if (y == 0) return x;
//return mgcd(y, x % y);
//}
typedef pair<string, int> pii;
bool cmp(pii a, pii b) {
if (a.first == b.first) {
return a.second > b.second;
}
return a.first < b.first;
}
signed main()
{
int n; cin >> n;
vector<pii>a(n), tmp(n);
for (int i = 0; i < n; i++) {
string s;
int p;
cin >> s >> p;
a[i] = { s,p };
}
tmp = a;
sort(a.begin(), a.end(), cmp);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (tmp[j] == a[i]) {
cout << j + 1 << endl;
break;
}
}
}
}
排好序后,找到原来的位置
C - Switches
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 300300 points
Problem Statement
We have �N switches with "on" and "off" state, and �M bulbs. The switches are numbered 11 to �N, and the bulbs are numbered 11 to �M.
Bulb �i is connected to ��ki switches: Switch ��1si1, ��2si2, ......, and ����siki. It is lighted when the number of switches that are "on" among these switches is congruent to ��pi modulo 22.
How many combinations of "on" and "off" states of the switches light all the bulbs?
#include<iostream>
#include <istream>
#include<algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <stack>
#include <sstream>
#include <stdlib.h>
#include <iomanip>
#include <utility>
//#define int long long
using namespace std;
//priority_queue <int> q;
//int mgcd(int x, int y)
//{
//if (y == 0) return x;
//return mgcd(y, x % y);
//}
const int N = 20;
int s[N][N],k[N],p[N],cnt[N];
int n,m,x,ans=0;
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
cin >> k[i];
for (int j = 1; j <= k[i]; j++)
{
cin >> x;
s[i][j] = x;
}
}
for (int i = 1; i <= m; i++)
cin >> p[i];
for (int i = 1; i <= (int)1 << n; i++)
{
for (int j = 1; j <= m; j++)
{
int count = 0;
for (int r = 1; r <= k[j]; r++)
{
if (i >> s[j][r] & 1)
count++;
}
cnt[j] = count;
}
ans++;
for (int t = 1; t <= m; t++)
{
if (cnt[t] % 2 == p[t])
continue;
else
{
ans--;
break;
}
}
}
cout << ans;
}
利用二进制枚举所有的结果,然后与p比较。(没ac)
D - equeue Editorial
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 400400 points
Problem Statement
Your friend gave you a dequeue �D as a birthday present.
�D is a horizontal cylinder that contains a row of �N jewels.
The values of the jewels are �1,�2,...,��V1,V2,...,VN from left to right. There may be jewels with negative values.
In the beginning, you have no jewel in your hands.
You can perform at most �K operations on �D, chosen from the following, at most �K times (possibly zero):
Operation A: Take out the leftmost jewel contained in �D and have it in your hand. You cannot do this operation when �D is empty.
Operation B: Take out the rightmost jewel contained in �D and have it in your hand. You cannot do this operation when �D is empty.
Operation C: Choose a jewel in your hands and insert it to the left end of �D. You cannot do this operation when you have no jewel in your hand.
Operation D: Choose a jewel in your hands and insert it to the right end of �D. You cannot do this operation when you have no jewel in your hand.
Find the maximum possible sum of the values of jewels in your hands after the operations.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int v[105];
signed main()
{
int n,k,ans=0;
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>v[i];
for(int i=0;i<=n;i++)
{
for(int j=0;j<=n;j++)
{
int m=k-i-j,sum=0;;
if(i+j>k)
continue;
priority_queue<int,vector<int>,greater<int> >s;
for(int x=1;x<=i;x++)
{
s.push(v[x]);
sum+=v[x];
}
for(int y=n;y>=n-j+1;y--)
{
s.push(v[y]);
sum+=v[y];
}
while(s.size()&&m>0&&s.top()<0)
{
sum-=s.top();
m--;
s.pop();
}
ans=max(ans,sum);
}
}
cout<<ans;
}
枚举每一种情况,左边拿几个?右边拿几个?如果还有次数放回去几个?