牛客每日練習----剪紙,聖誕節糖果,裁縫大師

我從前最怕旁人火眼金睛,如今,倒是盼着有人能夠洞幽燭遠。如此,就能贈我一點歡喜。

鏈接:https://ac.nowcoder.com/acm/problem/14654
來源:牛客網
 

題目描述

DD wants to send a gift to his best friend CC as her birthday is coming. However, he can’t afford expensive gifts, and he is so lazy that he is not willing to do complex things. So he decides to prepare a paper cut for CC’s birthday gift, which symbolizes their great friendship~~

DD has a square colored paper which consists of n*n small squares. Due to his tastes, he wants to cut the paper into two identical pieces. DD also wants to cut as many different figures as he can but each sheet can be only cut once, so he asks you how many sheets does he need to prepare at most.

for example:

輸入描述:

Input contains multiple test cases.
The first line contains an integer T (1<=T<=20), which is the number of test cases.Then the first line of each test case contains an integer n (1<=n<10).

輸出描述:

The answer;

示例1

輸入

複製

1
4

輸出

複製

11
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x7ffffff
#define P pair<int,int>
typedef long long ll;
using namespace std;
const ll MOD=1e9+7;
int T,n,vis[15][15],jg;
int fx[4][2]={0,1,1,0,0,-1,-1,0};
int fy[4][2]={0,-1,-1,0,0,1,1,0};
bool check(int x,int y){
    if(x<0||x>n||y<0||y>n||vis[x][y])
        return false;
    return true;
}
void dfs(int x1,int y1,int x2,int y2){
    if(x1==0||x1==n||y1==0||y1==n){
        jg++;
        return;
    }
    vis[x1][y1]=vis[x2][y2]=1;
    for(int i=0;i<4;i++){
        int X1=x1+fx[i][0];
        int Y1=y1+fx[i][1];
        int X2=x2+fy[i][0];
        int Y2=y2+fy[i][1];
        if(!check(X1, Y1)||!check(X2, Y2)) 
			continue;
        dfs(X1,Y1,X2,Y2);
    }
    vis[x1][y1]=vis[x2][y2]=0;
}
int main()
{
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        if(n%2){
            printf("0\n");
            continue;
        }
        jg=0;
        dfs(n/2,n/2,n/2,n/2);
        printf("%d\n",jg/4);
    }
    return 0;
}

鏈接:https://ac.nowcoder.com/acm/problem/14675
來源:牛客網

 

 

題目描述

聖誕節臨近,彩虹島的黑心商人𝑐𝑡𝑟的糖果店又開始熱鬧了起來,熱心的𝑠𝑙𝑝來到𝑐𝑡𝑟的店裏面幫忙包裝糖果。店裏面共有𝑛堆糖果,其中第𝑖堆有𝑎𝑖顆糖果,𝑐𝑡𝑟讓𝑠𝑙𝑝從中選擇兩堆糖果,這兩堆糖果中每𝑝 顆包裝在一起,如果最後還有剩餘就歸𝑠𝑙𝑝所有了,若兩堆不足𝑝個則全部歸𝑠𝑙𝑝所有。作爲糖果狂熱愛好者,𝑠𝑙𝑝當然是想拿走儘量多的糖果,因此他想知道自己最多能夠拿走多少糖果。

輸入描述:

輸入第一行爲一個整數𝑇(1 ≤ 𝑇 ≤ 10),表示一共有𝑇組測試數據。
對於每組測試數據:
第一行有兩個整數𝑛(2 ≤ 𝑛 ≤ 105), 𝑝(1 ≤ 𝑝 ≤ 109),分別表示糖果堆數和包裝後每包糖果的數量。
第二行有𝑛個整數,其中第𝑖個數𝑎𝑖(1 ≤ 𝑎𝑖 ≤ 109)表示第𝑖堆糖果的數量。

輸出描述:

對於每組測試數據,輸出一個整數𝑥表示𝑠𝑙𝑝能拿走的最多的糖果數目。

示例1

輸入

複製

2
4 5
1 4 2 3
4 15
12 19 13 20

輸出

複製

4
10

說明

對於第一組樣例,𝑠𝑙𝑝選擇第一堆和第四堆是最佳選擇,會剩餘4顆糖果。
對於第二組樣例,𝑠𝑙𝑝選擇第一堆和第三堆是最佳選擇,會剩餘10顆糖果。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x7ffffff
#define P pair<int,int>
typedef long long ll;
using namespace std;
const ll MOD=1e9+7;
int t,n,p,a[2*100010];
int main()
{
	scanf("%d",&t);
    while(t--)
    {
    	int ans=0,ct=1;
        scanf("%d %d",&n,&p);
        for(int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            x%=p;
            a[ct++]=x;
            a[ct++]=x-p;
        }
        sort(a+1,a+1+2*n,greater<int>());
        for(int i=1;i<=2*n;i++)
        {
            int d=lower_bound(a+1,a+1+2*n,p-a[i]-1,greater<int>())-a;
            if(d!=2*n+1&&d!=i&&abs(a[d]-a[i])!=p)
                ans=max(ans,(a[i]+a[d])%p);
        }
        printf("%d\n",ans);
    }
    return 0;
}

鏈接:https://ac.nowcoder.com/acm/problem/14676
來源:牛客網

 

 

題目描述

坤醬想把一塊圓形的布裁成正多邊形,於是請你告訴坤醬正多邊形的幾個頂點應在哪裏?

爲了方便表示,圓給出在座標系中,正多邊形的第一個頂點固定在該圓在平行於x軸正方向最遠的位置上,請按順時針順序輸出所有的頂點。

輸入描述:


 

輸入第一行給出單獨一個整數T,表示數據組數接下來T行,

每行順序給出四個整數x,y,R,N:

表示圓心爲(x,y),半徑爲R,裁出一個正N邊形。

−104≤x,y≤104,

0<R≤103,

3≤N≤50

輸出描述:

對於每組數據,輸出N行,從第一個頂點開始,按順時針順序輸出所有N個頂點的座標。
(由於坤醬工具有限,你只需保留2位小數)

示例1

輸入

複製

2
0 0 10 4
100 0 1 3

輸出

複製

10.00 0.00
0.00 -10.00
-10.00 0.00
0.00 10.00
101.00 0.00
99.50 -0.87
99.50 0.87

備註:

π可以用4 *atan(1.0)得到。
你需要避免輸出-0.00。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x7ffffff
#define P pair<int,int>
typedef long long ll;
using namespace std;
const ll MOD=1e9+7;
int t; 
int main(){
	cin>>t ;
    while(t--){
        int x,y,r,n ;
        scanf("%d%d%d%d",&x,&y,&r,&n) ;
        double pi=4*atan(1.0) ;
        for(int i=0;i<n; i++){
            printf ("%.2lf %.2lf\n",r*cos(2.0*pi-2.0*pi/n*i)+x+0.00000001,r*sin(2.0*pi-2.0*pi/n*i)+y+0.00000001);
        }
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章