Time Limit: 2 sec / Memory Limit: 256 MB
Score : points
Problem Statement Snuke has decided to play with a six-sided die. Each of its six sides shows an integer through , and two numbers on opposite sides always add up to .
Snuke will rst put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation:
Operation: Rotate the die toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain points where is the number written in the side facing upward.
For example, let us consider the situation where the side showing faces upward, the near side shows and the right side shows , as illustrated in the gure. If the die is rotated toward the right as shown in the gure, the side showing will face upward. Besides, the side showing will face upward if the die is rotated toward the left, the side showing will face upward if the die is rotated toward the front, and the side showing will face upward if the die is rotated toward the back.
Find the minimum number of operation Snuke needs to perform in order to score at least points in total.
Constraints
is an integer.
Input The input is given from Standard Input in the following format:
Output Print the answer.
Sample Input 1
7
Sample Output 1
2
Sample Input 2
149696127901
Sample Output 2
27217477801
因为筛子一开始是任意一个面的!!
所以在5、6之间徘徊即可。不断来回。
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL maxn = 100000+100;
int a[maxn];
int vis[maxn];
int main()
{
LL n;
cin>>n;
LL ans=n/11*2;
int mod=11;
n%=mod;
if(n>=1&&n<=6)ans++;
else if(n>=7&&n<=10)ans+=2;
cout<<ans;
}
D - Card Eater
Time Limit: 2 sec / Memory Limit: 256 MB
Score : points
Problem Statement Snuke has decided to play a game using cards. He has a deck consisting of cards. On the -th card from the top, an integer is written.
He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, is odd, which guarantees that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
Constraints
is odd.
is an integer.
Input The input is given from Standard Input in the following format:
...
Output Print the answer.
Sample Input 1
5 1 2 1 3 7
Sample Output 1
3
One optimal solution is to perform the operation once, taking out two cards with and one card with . One card with and another with will be eaten, and the remaining card with will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: , and .
Sample Input 2
15 1 3 5 2 1 3 2 8 8 6 2 6 11 1 1
Sample Output 2
7
这个题要统计除1之外其他数的个数S,若S为奇数就输出S,否则输出S-1
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL maxn = 100000+100;
int a[maxn];
int vis[maxn];
int main()
{
//cout<<149696127901/6<<endl;
int n;
int ans=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(!vis[a[i]])
vis[a[i]]++,ans++;
}
if(ans%2)printf("%d\n",ans);
else printf("%d\n",ans-1);
}