本文共 5851 字,大约阅读时间需要 19 分钟。
虽说还在Pending,但是已经万念俱灰了……
已经知道了自己的C题PrePassed注定会变成SystemTestFailed了……因为先INT乘后LongLong强制转换一定会溢出……哭瞎……
然后又犯了这个该死的错误……忘了注释掉freopen交了两发WA,反正这回死定了……
这题是说,如果发现有两种电脑,便宜的性能更好则HA,否则PA
那么我们就用pair存然后排序(我用的是优先队列自动维护顺序),然后遍历一遍,如果相邻的两个价格大的性能低则输出HA,遍历完都没有这种情况的话输出PA
Code:
#include #include #include #include #include #include #include #include #include using namespace std;int main(){ int n; cin>>n; priority_queue > pq; while(!pq.empty())pq.pop(); for(int i=0;i >a>>b; pq.push(make_pair(a,b)); } int la=-1,lb=-1,flag=0; while(!pq.empty()) { pair tmp=pq.top();pq.pop(); //cout< <<"\t"< < lb){flag=1;break;} lb=tmp.second; } } if(!flag)puts("Poor Alex"); else puts("Happy Alex"); return 0;}
Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:
(1n + 2n + 3n + 4n) mod 5 for given value of n. Fedya managed to complete the task. Can you? Note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).
Print the value of the expression without leading zeros.
Operation x mod y means taking remainder after division x by y.
Note to the first sample:

这题问(1^n+2^n+3^n+4^n)Mod 5是多少。n可以各种大。
我们知道,1~4的n次幂mod5是有规律的:
1) 1 1 1 1
2) 2 4 3 1
3) 3 4 2 1
4) 4 1 4 1
Sum 0 0 0 4
所以我们只需要知道这个好长好长的数字mod4是多少就行了,然而,一个数字mod4的话我们只需要判断后2位是否mod4=0即可。
这里我用的是割位法,这个不只针对4,其他的数字也可以适用,较为普适的算法:(啊啊啊啊啊这里我freopen交了2发WA呀 啊啊啊啊啊)
Code:
#include #include #include #include #include #include #include #include using namespace std;int main(){ char c; int now = 0; //freopen("in.txt","r",stdin); while(1) { if(scanf("%c",&c)==EOF)break; if(isdigit(c)) { now=now*10 + (c-'0'); now=now%4; } else break; } if(!now)cout<<"4"; else cout<<"0"; return 0;}
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and delete it, at that all elements equal toak + 1 and ak - 1 also must be deleted from the sequence. That step brings ak points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Print a single integer — the maximum number of points that Alex can earn.
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
哭瞎的一题……这题用dp做……
首先读入,m[a]为a出现的个数,用a从大到小排序,cnt计数。
那么—— REP (cnt,0,n)
1)对于当前这个数a —— 如果a-1的数字没有出现过,那么dp[now]=dp[now-1]+a*m[a].(就是这里,要改成(long long)a*m[a])
2)当a-1出现过的话,dp[now]=max(dp[now-1],dp[now-2]+(long long)a*m[a])
Ex) 既然有now-1.now-2,那么1、2要记得特判哦,免得RE了
Code:
#include
转载地址:http://bnwi.baihongyu.com/