2018_清明第一场

  • 根本不会了- -
  • vj 关闭 csdn 启动
  • A - Alice and Bob and Cue Sports
  • Alice and Bob both love playing games. Now, Alice and Bob are playing a cue sport like Nine-ball Pool. Two players move in turn. A move is that one player use the cue ball to hit the target ball for pocketing the target ball. At the beginning of game, there are one cue ball and n object balls. Each object ball has a number (a positive integer) on it, and no two object balls have the same number. In a move, the target ball is a object ball still on the table with the smallest number. If the player does the following things in a move, a foul is called and a penalty point is added to the opposite’s point:

Cue ball do not hit any object ball. Penalty: the number of target ball.
Cue ball is not pocketed and hit at least one ball, but do not hit target ball first or hit more than one object ball first at the same time. Penalty: the largest number of ball in the first hit balls.
Cue ball is pocketed and hit at least one ball. Penalty: the largest number of ball in the first hit balls.
If the player pockets the target ball without a foul, a point will be added to the player’s points, which is the sum of numbers of the ball pocketed in this move, and the player can make another move. But, if the player pockets the target ball with a foul or pockets at least one object ball not including the target ball, this point will be added to the opposite’s points. If cue ball is pocketed, it will be pull out of the pocket and put on the table again while object balls will not be put on the table again after they are pocketed, even if the player pocketed them with a foul.
Now given n object balls and m moves, Bob wants to write a program to calculate the final points of Alice and him after these m moves. Because of Lady’s first Rule, Alice always moves first.

Input
There are multiple cases. The first line of each case consists of two integers, n and m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 1000), as described above. The second line consists of n positive integers. Each integer ai means the number of ith object ball (1 ≤ ai ≤ 10000). There are 2m lines followed. The (2i-1)th and (2i)th lines describe the ith move. The (2i-1)th line first includes an integer p, meaning cue ball hits p balls first. There are p integers followed in the same line, describing the hit balls. The (2i)th line first includes an integer q, meaning there are q balls pocketed. There are q integers followed in the same line, describing the pocketed balls (0 means cue ball). It’s guaranteed that there is no impossible data.

Output
For each case, output one line as the format: “AP : BP”, where AP means Alice’s points and BP means Bob’s points.

Sample Input
3 3
2 3 5
1 2
1 2
1 3
1 5
1 3
1 3
Sample Output

  • 台球规则
  • 当犯规又进球的情况下要给对手加两次分
  • 这是个模拟题
  • 弄清楚规则就可以写出来了
#include 
#include 
#include 
#include 
#include 
using namespace std;
set <int> ball;     //场上的球
int allPoint[2];    //二者总分
int nowTurn;        //先手
int nextTurn;       //后手
int i,j;            //循环用
int n,m,b,p,q;      //就是题意上那些 b->球:输入
int target;         //当前目标球
int maxScore;       //目标最大得分
int score;          //每回合得分
bool targetIn;      //目标球进袋
bool whiteIn;       //白球进袋

void rule(){
    if(p == 0 || maxScore > target || whiteIn){
        whiteIn = 1;                 //白球进
        allPoint[nextTurn] += maxScore; //犯规分
    }
    if(!targetIn)   whiteIn = 1;
    if(whiteIn){
        allPoint[nextTurn] += score;
        swap(nowTurn,nextTurn);      //换人
    }else{
        allPoint[nowTurn] += score;
    }
}
int main(){
    while(~scanf("%d%d",&n,&m)){
        ball.clear();       //清空球
        memset(allPoint, 0, sizeof(allPoint));  //总分数归零
        for(i = 1;i <= n;i++){
            scanf("%d",&b);
            ball.insert(b);
        }
        nowTurn = 0;
        nextTurn = 1;
        while(m--){
            target = *ball.begin();
            maxScore = target;
            scanf("%d",&p);
            for(j = 1;j <= p;j++){
                int t;
                scanf("%d",&t);
                maxScore = max(maxScore,t); //犯规得分,击中最大
            }
            score = 0;
            targetIn = 0;
            whiteIn = 0;
            scanf("%d",&q);
            while(q--){
                int t;
                scanf("%d",&t);     //进球情况
                if(t == 0)  whiteIn = true;
                else if(t == target)targetIn = true;
                ball.erase(t);
                score += t;
            }
            //犯规情况
            rule();
        }
        cout<0]<<" : "<1]<return 0;
}
  • B - Singles’ Day

Singles’ Day(or One’s Day), an unofficial holiday in China, is a pop culture entertaining holiday on November 11 for young Chinese to celebrate their bachelor life. With the meaning of single or bachelor of number ‘1’ and the huge population of young single man. This festival is very popular among young Chinese people. And many Young bachelors organize parties and Karaoke to meet new friends or to try their fortunes that day.

On Singles’ Day, a supermarket has a promotional activity. Each customer will get a ticket on which there are two integers b and N, representing an integer M that only contains N digits 1 using b as the radix. And if the number M is a prime number, you will get a gift from the supermarket.

Since there are so many customers, the supermarket manager needs your help.

Input
There are multiple test cases. Each line has two integers b and N indicating the integer M, which might be very large. (2 <= b <= 16, 1 <= N <= 16)

Output
If the customer can get a gift, output “YES”, otherwise “NO”.

Sample Input
3 3
2 4
2 1
10 2
Sample Output
YES
NO
NO
YES
Hint
For the first sample, b=3, N=3, so M=(111)3, which is 13 in decimal. And since 13 is a prime number, the customer can get a gift, you should output “YES” on a line.

  • 题意是由N个1组成的b进制
  • 转成十进制,判断是否质数
#include 
#include 
#include 
using namespace std;
#define ll long long
ll num,a,b,i;
int prime (ll n){
    if(n == 1)  return 0;
    else{
        for(i = 2; i * i <= n;i++){
            if(n%i==0)
                return 0;
        }
    }
    return 1;
}
int main(){
    while(~scanf("%lld %lld",&a,&b)){
        num = 0;
        for(i=b-1;i>=0;i--){
            num = num + pow(a,i);   //转乘十进制
        }
        if(prime(num)){             //判断质数
            cout<<"YES"<else{
            cout<<"NO"<return 0;
}
  • E题
  • TLE。。。待解决
#include 
#include 
#include 
using namespace std;

double MAX_H = 0.0;

typedef struct node{
    double x;
    double y;
}NODE;

int main(){
    int n;
    while(~scanf("%d",&n)){
        MAX_H = 0.0;
        NODE nd[5500];
        for(int i = 0;i < n;i++){
            scanf("%lf %lf",&nd[i].x,&nd[i].y);
        }
        for(int i = 0;i < n-2;i++){
            for(int j = i+1;j < n-1;j++){
                for(int k = j+1;k < n;k++){
                    double A = sqrt(fabs(pow(nd[i].x - nd[j].x,2) + pow(nd[i].y - nd[j].y,2)));
                    double B = sqrt(fabs(pow(nd[i].x - nd[k].x,2) + pow(nd[i].y - nd[k].y,2)));
                    double C = sqrt(fabs(pow(nd[k].x - nd[j].x,2) + pow(nd[k].y - nd[j].y,2)));
                    double p = 0.50 * (A+B+C);
                    double S = sqrt(p*(p-A)*(p-B)*(p-C));
                    double h1 = 2*S/A;
                    double h2 = 2*S/B;
                    double h3 = 2*S/C;
                    double h = max(max(h1,h2),h3);
                    if(h > MAX_H) MAX_H = h;
                }
            }
        }
        printf("%.5f\n",MAX_H);
    }
    return 0;
}

你可能感兴趣的:((qty)2018_清明第一场)