Risk Rolls
Time limit:
1000 ms Memory limit:
256 MB Alena and Boris are playing Risk today. We'll call an outcome the sum of values on the faces of 111 or more rolled dice. Alena has NNN possible outcomes whilst Boris has MMM. In turns, each one of them will choose their best possible available outcome and play it. If Alena's outcome is strictly greater than Boris's, then Alena wins; otherwise Boris wins. Whenever one of them runs out of outcomes, the game ends.
In how many turns does Alena win? What about Boris?
Standard input
The first line contains two integers NNN and MMM.
The second contains NNN integers, Alena's possible outcomes.
The third line contains MMM integers, Boris's possible outcomes.
Standard output
Print two integers AAA and BBB on the first line of the output; AAA represents the number of turns won by Alena and BBB the number of turns won by Boris.
Constraints and notes
- 1≤N,M≤101 \leq N, M \leq 101≤N,M≤10
- 1≤v≤241 \leq v \leq 241≤v≤24, where vvv is a possible outcome value
Input | Output | Explanation |
1 3241 2 3 | 1 0 | In the first turn, Alena will play 242424, which will beat Boris's 333 |
3 12 1 324 | 0 1 | This is the first sample with reversed outcomes for Alena and Boris. |
2 210 15 5 | 1 1 | |
4 33 4 5 249 9 9 | 1 2 | In the first turn Alena will beat Boris because she will play 242424. |
3 38 9 1010 8 8 | 1 2 | In the first turn they will play 101010 against 101010 and Boris will win. On the second turn they will play 999 versus 888 and Alena will win. The third turn is also won by Boris. |
直接做就好了,排序,注意有个strictly就是大于
#include using namespace std;int a[15],b[15];int cmp(int a,int b){ return a>b;}int main(){ int n,m; cin>>n>>m; int mi=min(n,m); for(int i=0;i >a[i]; for(int i=0;i >b[i]; sort(a,a+n,cmp); sort(b,b+n,cmp); int af=0,bf=0; for(int i=0;i b[i])af++; else bf++; cout< <<" "<
Processing Discounts
Time limit:
1000 ms Memory limit:
256 MB You've just placed an order of XXX USD on an online shopping website. The website has NNN special discounts: if you make a purchase of at least AiA_iAi USD, you get back BiB_iBi USD. It may be advantageous to increase your order bill just so you would be eligible of certain discount offers.
What's the minimum amount of USD that you have to pay in the end, after processing the discounts?
Standard input
The first line contains two integers, NNN and XXX.
The next NNN lines contain a pair of integers, AiA_iAi and BiB_iBi.
Standard output
Print the answer on the first line.
Constraints and notes
- 1≤N≤1051 \leq N \leq 10^51≤N≤105
- 1≤X,Ai,Bi≤1061\leq X, A_i, B_i \leq 10^61≤X,Ai,Bi≤106
- The online shopping website will never become in debt to you, i.e. the discount offers are chosen in such a way that you'd never reach a negative amount of payment.
Input | Output | Explanation |
3 9950 575 10100 5 | 80 | We're eligible for the first two discount offers, so we get 5+10=155 + 10 = 155+10=15 USD back. This means that in the end we'll pay 99−15=8499 - 15 = 8499−15=84 USD. If we increase our order up to 100100100 USD, we'll be eligible for the third offer as well and we'll pay only 100−5−10−5=80100 - 5 - 10 - 5 = 80100−5−10−5=80 USD. |
5 5010 120 230 330 3100 10 | 41 | We're eligible for all the discount offers besides the last one. If we were to increase our payment in order to get the last offer, we would end up with 100−10−3−3−2−1=81100 - 10 - 3 - 3 - 2 - 1 = 81100−10−3−3−2−1=81 USD. It's better to only consider the first 333, we end up spending 50−3−3−2−1=4150 - 3 - 3 - 2 - 1 = 4150−3−3−2−1=41 USD. |
1 10100 95 | 5 | |
1 200100 95 | 105 | |
B就是一个优惠券的问题,排下序,找到付款最小值就行了
#include using namespace std;int n,x;const int N=1e5+5;pair a[N];int main(){ scanf("%d%d",&n,&x); for(int i=0; i
Counting Quacks
Time limit:
1000 ms Memory limit:
256 MB There are NN ducks on a lake. Every duck ii quacks periodically, once every X_iXi moments of time; i.e. it quacks for the first time at the X_i^{\text{th}}Xith moment of time, it quacks for the second time at the {2 * X_i}^{\text{th}}2∗Xith moment and so on...
Alex is sitting near this lake and he asks himself:
- What's the maximum number of quacks i'll hear at the same moment of time?
- How many times i'll hear this many quacks throughout my staying at the lake?
Alex isn't feeling so contemplative today, so he's leaving the lake after TT moments of time. After he leaves he won't be able to hear any more quacks.
Standard input
The first line contains two integers, NN and TT.
The next line contains NN integers representing XX.
Standard output
The first line contains two integers separated by space, as described in the statement.
Constraints and notes
- 1 \leq N \leq 10^51≤N≤105
- 1 \leq T \leq 10^61≤T≤106
- 1 \leq X_i \leq 10^61≤Xi≤106 for each 1 \leq i \leq N1≤i≤N
- Alex comes at the lake at the moment of time 11.
Input | Output |
3 62 2 3 | 3 1 |
3 52 2 3 | 2 2 |
6 101 2 3 4 5 6 | 4 1 |
C当时太脑残了,没想到正确的做法,甚至想着去维护这些数,但是T不大啊,直接用埃筛的思想处理下就行了,复杂度O(T+TogT)
#include using namespace std;const int N=1e6+5;int n,T,a[N],M[N];int main(){ scanf("%d%d",&n,&T); for(int i=0,x; i ans)ans=a[i],cnt=1; else if(a[i]==ans) cnt++; printf("%d %d\n",ans,cnt); return 0;}
Flipping Matrix
Time limit:
1000 ms Memory limit:
256 MB You are given a binary matrix AA of size N \times NN×N. You are allowed to perform the following two operations:
- Take two rows and swap them. If we want to swap rows xx and yy, we'll encode this operation as
R x y
. - Take two columns and swap them. If we want to swap columns xx and yy, we'll encode this operation as
C x y
.
Is it possible to obtain only values of 11 on the of AA by performing a sequence of at most NN operations? If so, print the required operations.
Standard input
The first line contains NN.
The next NN lines contain NN binary values separated by spaces, representing AA.
Standard output
If there is no solution, print -1−1.
Otherwise, print every operation on a separated line.
Constraints and notes
- 2 \leq N \leq 10^32≤N≤103
- 0 \leq A_{i, j} \leq 10≤Ai,j≤1 for every 1 \leq i, j \leq N1≤i,j≤N
Input | Output |
30 0 10 1 01 0 0 | C 1 3 |
41 1 0 00 1 0 11 1 0 00 0 0 1 | -1 |
50 1 0 0 10 0 1 0 00 1 0 0 00 0 1 1 01 0 0 0 0 | R 1 5C 2 3 |
是个特判题,虽说可以交换行和列,但是其实交换哪个都一样,dfs遍历看看有没有机会得到对角线全是1,需要优秀的暴力,因为n还是很大的
#include using namespace std;const int N=1005;int a[N][N],F[N],n,y[N];int dfs(int x){ for(int i=1; i<=n; i++) if(a[x][i]&&!y[i]) { y[i]=1; if(!F[i]||dfs(F[i])) { F[i]=x; return 1; } } return 0;}int la(){ for(int i=1; i<=n; i++) { memset(y,0,sizeof y); if(!dfs(i))return 0; }return 1;}int main(){ scanf("%d",&n); for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) scanf("%d",a[i]+j); if(!la())puts("-1"); else { for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(F[j]==i) { if(j!=i)swap(F[j],F[i]),printf("C %d %d\n",i,j); break; } } return 0;}