Codeforces #199前三題

果7發表於2013-09-07

先寫下總結,當時第三題被黑了是好事情。自己當時想到了那種三個圓相切的局面,但後來又被自己給否定了,應該多畫畫圖就出來了,不應該那樣老是空想。而且需要搞個圓規了!


A. Xenia and Divisors
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Xenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three a, b, c the following conditions held:

  • a < b < c;
  • a divides bb divides c.

Naturally, Xenia wants each element of the sequence to belong to exactly one group of three. Thus, if the required partition exists, then it has  groups of three.

Help Xenia, find the required partition or else say that it doesn't exist.

Input

The first line contains integer n (3 ≤ n ≤ 99999) — the number of elements in the sequence. The next line contains n positive integers, each of them is at most 7.

It is guaranteed that n is divisible by 3.

Output

If the required partition exists, print  groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.

If there is no solution, print -1.

Sample test(s)
input
6
1 1 1 2 2 2
output
-1
input
6
2 2 1 1 4 6
output
1 2 4
1 2 6

      題目大意:那個divides是整除的意思,開始看了一段時間,小數除以大數什麼意思?給你1-7很多數,分成很多組,每組有a,b,c,a<b<c且a|b,b|c。解題思路就很簡單了,因為只能a<b<c,並且有整除關係只有1 2 4 ,1 2 6, 1 3 6三組。假設1,2,4的個數為a個,1, 2, 6的個數為b個,1, 3, 6的個數為c個。1就有a+b+c,2就有a+b,3就有c,4就有a,6就有b+c,5和7是0。這樣判斷即可。詳見程式碼。


   題目地址:A. Xenia and Divisors


AC程式碼:

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int p[8];

int main()
{
    int i,n,x;
    while(~scanf("%d",&n))
    {
        memset(p,0,sizeof(p));
        for(i=0;i<n;i++)
        {
            scanf("%d",&x);
            p[x]++;
        }
        if(p[5]>0||p[7]>0)
        {
            puts("-1");
            continue;
        }

        int a,b,c;
        a=p[4],c=p[3],b=p[1]-a-c;
        if(b<0)
            puts("-1");
        else
        {
            if(p[2]==a+b&&p[6]==b+c)
            {
                for(i=0;i<a;i++)
                    printf("1 2 4\n");
                for(i=0;i<b;i++)
                    printf("1 2 6\n");
                for(i=0;i<c;i++)
                    printf("1 3 6\n");
            }
            else
                puts("-1");
        }

    }
    return 0;
}


B. Xenia and Spies
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right.

Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the note to one of his neighbours in the row. In other words, if this spy's number is x, he can pass the note to another spy, either x - 1 or x + 1 (if x = 1 or x = n, then the spy has only one neighbour). Also during a step the spy can keep a note and not pass it to anyone.

But nothing is that easy. During m steps Xenia watches some spies attentively. Specifically, during step ti (steps are numbered from 1) Xenia watches spies numbers li, li + 1, li + 2, ..., ri (1 ≤ li ≤ ri ≤ n). Of course, if during some step a spy is watched, he can't do anything: neither give the note nor take it from some other spy. Otherwise, Xenia reveals the spies' cunning plot. Nevertheless, if the spy at the current step keeps the note, Xenia sees nothing suspicious even if she watches him.

You've got s and f. Also, you have the steps during which Xenia watches spies and which spies she is going to watch during each step. Find the best way the spies should act in order to pass the note from spy s to spy f as quickly as possible (in the minimum number of steps).

Input

The first line contains four integers nms and f (1 ≤ n, m ≤ 105; 1 ≤ s, f ≤ ns ≠ fn ≥ 2). Each of the following m lines contains three integers ti, li, ri (1 ≤ ti ≤ 109, 1 ≤ li ≤ ri ≤ n). It is guaranteed that t1 < t2 < t3 < ... < tm.

Output

Print k characters in a line: the i-th character in the line must represent the spies' actions on step i. If on step i the spy with the note must pass the note to the spy with a lesser number, the i-th character should equal "L". If on step i the spy with the note must pass it to the spy with a larger number, the i-th character must equal "R". If the spy must keep the note at the i-th step, the i-th character must equal "X".

As a result of applying the printed sequence of actions spy s must pass the note to spy f. The number of printed characters k must be as small as possible. Xenia must not catch the spies passing the note.

If there are miltiple optimal solutions, you can print any of them. It is guaranteed that the answer exists.

Sample test(s)
input
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
output
XXRR

          題目大意:給你n個人,每次只能往左走一步,或往右走一步。從s走到f問你最小走的路徑,但是有m個規定,規定在第ti步的時候,從li到ri的位置都不能動。我的想法就是每次要麼停著X,要麼往右走。開始把if(s>f) swap(s,f)。開始犯2了。那樣的話,需要輸出往左走就只能哭瞎了!如果s<f要麼停著X,要麼往右走,如果s>f要麼停著X,要麼往左走。具體見程式碼。


 AC程式碼:

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int t[100005],l[100005],r[100005];  

int main()
{
    int n,m,s,f,i;
    while(~scanf("%d%d%d%d",&n,&m,&s,&f))
    {
        if(s<f)  //往右走或停
        {
            for(i=1; i<=m; i++)
                scanf("%d%d%d",&t[i],&l[i],&r[i]);
            int step=1;
            int pos=1;
            while(s<f)  //如果s<f就停止
            {
                while(t[pos]<step) pos++;  //比它步數小的都過濾掉
                if(step<t[pos])
                {
                    s++;
                    step++;
                    cout<<"R";
                }
                else if(step==t[pos])
                {
                    if(s<l[pos]-1||s>r[pos])  //不在li到ri之內
                    {
                        s++;
                        step++;
                        cout<<"R";
                    }
                    else  ////在li到ri之內
                    {
                        step++;
                        cout<<"X";
                    }
                }
            }
            cout<<endl;
        }

        else  //往左走或停
        {
            for(i=1; i<=m; i++)
                scanf("%d%d%d",&t[i],&l[i],&r[i]);
            int step=1;
            int pos=1;
            while(s>f)
            {
                while(t[pos]<step) pos++;
                if(step<t[pos])
                {
                    s--;
                    step++;
                    cout<<"L";
                }
                else if(step==t[pos])
                {
                    if(s>r[pos]+1||s<l[pos])  //不在li到ri之內
                    {
                        s--;
                        step++;
                        cout<<"L";
                    }
                    else  //在li到ri之內
                    {
                        step++;
                        cout<<"X";
                    }
                }
            }
            cout<<endl;
        }
    }
    return 0;
}

/*
3 5 1 3
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
3 5 3 1
1 1 2
2 2 3
3 3 3
4 1 1
10 1 3
*/


C. Cupboard and Balloons
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectangle with base r and height h + r from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right).

Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius . Help Xenia calculate the maximum number of balloons she can put in her cupboard.

You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin.

Input

The single line contains two integers r, h (1 ≤ r, h ≤ 107).

Output

Print a single integer — the maximum number of balloons Xenia can put in the cupboard.

Sample test(s)
input
1 1
output
3
input
1 2
output
5
input
2 1
output
2

  題目大意:題目意思很簡單,左邊的是正面圖,右邊的圖片是左檢視。問你放半徑為r/2.0的球最多能放多少個。由於半徑是r/2.0,直接可以轉換為二維平面上能含最多的圓。這個題目主要需要分類討論,詳見程式碼,開始只分了兩類。但是結果被黑了,待會兒下面有圖解,主要是有一種情況沒有看到。在最後的十分鐘的時候看到這個問題,當時沒有認真想三圓相切,而是直接飄過了。。沒有動筆畫圖的缺點暴露了。。



詳見AC程式碼:

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    double h,r;
    int sum=0;
    while(~scanf("%lf%lf",&r,&h))
    {
        int p=(int)(h/r);
        if(h-r*p>=r/2.0*(sqrt(3.0)))
            sum=p*2+3;
        else if(h-r*p>=r/2.0)
            sum=p*2+2;
        else
            sum=p*2+1;
        cout<<sum<<endl;
    }
    return 0;
}



剛為了準備畫圖,結果重新下ps cs6結果中木馬了,桌面動不了了。開機了最後dns服務也被篡改了。搞了半天還是搞好了。。。!

開啟網路中心--網路介面卡。。ip可以自動獲取沒得問題。主要是dns伺服器地址。當你可以上網的時候就按此處操作:點選左下角“開始”——“執行”—— 輸入“cmd”確定——在命令提示符中輸入“ipconfig/all”,之後就會顯現DMS伺服器地址,記住那個地址,把那個dns地址在本地連線的屬性中寫入就不會斷網了。(開始上網時候都是自動獲取的) 。


相關文章