9.9训练日志

来源:互联网 发布:怎么上淘宝的每日好店 编辑:程序博客网 时间:2024/05/29 18:07

Bachgold Problem

Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.

Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.
拆一个数成尽可能多数,大水题,分解成一堆2,如果偶数去个2补个3就ok

#include<bits/stdc++.h>using namespace std;int main() {    int n,i,ans=0;    cin>>n;    if(n&1) {        ans=ans+(n/2);        cout<<ans<<endl;        for(i=1; i<ans; i++)            cout<<2<<" ";            cout<<3<<" ";    } else {        ans=ans+(n/2);        cout<<ans<<endl;        for(i=1; i<=ans; i++)            cout<<2<<" ";    }    return 0;}

Parallelogram is Back

Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.

Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points.
也是个水题,给平行四边形三点点坐标,求第四点可能情况
唯一要注意的是算中点要用到double…

#include<bits/stdc++.h>using namespace std;int main() {    int i;double a[4],b[4],c[4],d[4];    for(i=1;i<=3;i++)    {cin>>a[i]>>b[i];    }    c[1]=(a[1]+a[2])/2;    c[2]=(a[1]+a[3])/2;    c[3]=(a[2]+a[3])/2;    d[1]=(b[1]+b[2])/2;    d[2]=(b[1]+b[3])/2;    d[3]=(b[2]+b[3])/2;    cout<<3<<endl;    cout<<(2*c[1]-a[3])<<" "<<d[1]-(b[3]-d[1])<<endl;    cout<<c[2]-(a[2]-c[2])<<" "<<d[2]-(b[2]-d[2])<<endl;    cout<<c[3]-(a[1]-c[3])<<" "<<d[3]-(b[1]-d[3])<<endl;}

Voting

There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.

Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:

Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it’s time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).
When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It’s allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.
When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements.
The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.
稍有难度的题,在比赛结束前几秒才写出来…意思是两派d,r,从头开始轮,轮到d可以杀一个r,轮到r可杀个d,重复直至只有一个幸存者,幸存者是哪一派就输出它.用正常写法%100要tle,因此选择队列.

#include<bits/stdc++.h>using namespace std;int main() {    int n,i,k1=0,k2=0,a[200010]={0};    char m[200010],ans;    bool l=0;    queue<char>d,r;    cin>>n;    cin>>m;    for(i=0;i<n;i++)    {if(m[i]=='D')d.push(m[i]);     if(m[i]=='R')r.push(m[i]);    }    while(!d.empty()||!r.empty())     {for(i=0;i<n;i++)       {if(a[i]!=0)continue;        if(m[i]=='D')         {if(k2>0)           {d.pop();k2--;a[i]=1;           }          else if(k2==0)           {k1++;            } }        else if(m[i]=='R')          {if(k1>0)            {r.pop();k1--;a[i]=1;            }           else if(k1==0)              k2++;                  }               if(d.empty()||r.empty())          break;         }         if(d.empty()||r.empty())          break;     }    if(d.size()==0)    ans=r.front();    else ans=d.front();    cout<<ans;//<<" "<<c.size()<<" "<<b.size();}

Secrets

Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen.

One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?

The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of n marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least n marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want.
水题,求价格不能整除的最小的3的幂,再除以一下就行了

#include<bits/stdc++.h>using namespace std;int main() {    long long int n,i,ans=0;    cin>>n;    for(i=3;i<=n;i=i*3)    {if(n%i!=0)      {ans=n/i;break;      }    }    cout<<ans+1;}

Chips

Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases:

At least one of the chips at least once fell to the banned cell.
At least once two chips were on the same cell.
At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row).
In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.
也较水,一个棋盘,从某一边不是角的一点开始走格子,不碰坏点到对岸就行.注意奇数乘奇数棋盘要特判,中心点横向纵向(如果没坏点)棋子会相撞因此要-1.

#include<bits/stdc++.h>using namespace std;int main() {   int n,m,x,y,i,ans1,ans2;bool map1[1010]={0},map2[1010]={0};   cin>>n>>m;   ans1=n-2;ans2=n-2;   for(i=1;i<=m;i++)    {cin>>x>>y;    map1[x]=1;map2[y]=1;    }    for(i=2;i<=n-1;i++)    {if(map1[i]==1)ans1--;     if(map2[i]==1)ans2--;    }    if(n&1&&map1[(n+1)/2]==0&&map2[(n+1)/2]==0)     ans1--;cout<<ans1+ans2;    } 

总结:

可能是周末,题目比较简单,但我也是最后几秒才做掉第三题ak,因此还要加快写代码速度..

原创粉丝点击