牛客每日練習----逆序對,星圖,小周的曲射炮

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

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

題目描述

求所有長度爲n的01串中滿足如下條件的二元組個數:
設第i位和第j位分別位ai和aj(i<j),則ai=1,aj=0。
答案對1e9+7取模。
 

輸入描述:

輸入一個n。

輸出描述:

輸出答案對1e9+7取模

示例1

輸入

複製

3

輸出

複製

6

說明

備註:

 n <= 1018
#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;
ll n,jg;
ll kpow(ll a,ll b){
    ll jg=1,base=a;
    while(b>0){
        if(b&1)
            jg=(jg%mod)*(base%mod)%mod;
        b=b>>1;
        base=(base%mod)*(base%mod)%mod;
    }
    return jg;
}
int main(){
    scanf("%lld",&n);
    jg=((n%mod)*((n-1)%mod))/2%mod;
    jg=((jg%mod)*(kpow(2,n-2)%mod))%mod;
    printf("%lld\n",jg);
    return 0;
}

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

 

 

題目描述

 

現在有一個N*M的矩形星圖。其中包括恆星和黑洞。恆星可以向上、下、左、右發射光束,且允許光束從其中穿過;黑洞會吸收所有經過的光束。

若一顆恆星向上、下、左、右發射光束,你能告訴我,該光束能否避免被黑洞吸收,進入星圖之外的區域麼?

 

輸入描述:

單組輸入。第一行三個正整數N,M,Q(1 <= N,M
<= 1000,1 <= Q <= 1000000),分別表示矩陣的行列,以及詢問的個數,詢問之間相互獨立。
然後一個N*M的矩陣,由’*’和’#’構成,表示星圖。’*’表示恆星,’#’表示黑洞。
最後Q行,表示Q個詢問,每行兩個正整數x,y(1 <= x <= N, 1 <= y
<= M)表示發光恆星的位置(從上往下數第x行,從左往右數第y列,且保證該位置一定是恆星)和一個字符p(p∈{‘L’, ‘R’,
‘D’, ‘U’},’R’表示向右;’L’表示向左;’D’表示向下’;’U’表示向上)表示該恆星產生光束的方向。

輸出描述:

一共Q行。對於每個詢問,若該恆星發出的光束能夠進入星圖之外的區域則輸出“YES”;否則輸出“NO”。(不包含引號)

示例1

輸入

複製

4 5 5
**##*
*****
*#*#*
##**#
2 3 D
2 3 U
1 5 R
4 4 U
3 1 U

輸出

複製

YES
NO
YES
NO
YES
#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;
char mp[1010][1010],op[10];
int n,m,q,x,y;
bool fgl[1010][1010],fgr[1010][1010],fgu[1010][1010], fgd[1010][1010];
int main()
{
    cin>>n>>m>>q;
    for(int i=0;i<n;i++)
        cin>>mp[i];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m&&mp[i][j]=='*';j++)
            fgl[i][j]=1;
        for(int j=m-1;j>=0&&mp[i][j]=='*';j--)
            fgr[i][j]=1;
    }
    for(int j=0;j<m;j++)
    {
        for(int i=0;i<n&&mp[i][j]=='*';i++)
            fgu[i][j]=1;
        for(int i=n-1;i>=0&&mp[i][j]=='*';i--)
            fgd[i][j]=1;
    }
    while(q--)
    {
        scanf("%d%d%s",&x,&y,op);
        x--,y--;
        if(op[0]=='L'&&fgl[x][y])
			cout<<"YES\n";
        else if(op[0]=='R'&&fgr[x][y])
			cout<<"YES\n";
        else if(op[0]=='U'&&fgu[x][y])
			cout<<"YES\n";
        else if(op[0]=='D'&&fgd[x][y])
			cout<<"YES\n";
        else 
			cout<<"NO\n";
    }
    return 0;
}

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

 

 

題目描述

小周最近在玩一款二戰遊戲,他因而對曲射炮的軌跡產生了很大的興趣,但是在嘗試計算後,小周發現這個問題並不是那麼簡單,他因而來請教你這位計算機高手,請你來幫幫他吧。問題大致可描述爲,在二維平面的原點(0,0)處有一曲射炮,炮口可沿任意方向發出初速度爲v的炮彈,小周想要把炮彈投射到點(x,y)處,現在你需要幫助小周得出炮口與地面夾角的弧度。爲使問題簡化,我們忽略空氣阻力,x軸沿水平方向分佈。設重力加速度g=9.8。
 

輸入描述:

第一行爲一個整數T,表示輸入的數據組數。
每組數據對應一行輸入, 依次爲三個正整數x,y,v,含義如題面所示。

輸出描述:

每組數據輸出一行,如果無論如何挑戰炮口與地面夾角都無法將炮彈投射這目標處,輸出“NO SOLUTION.”(不包括引號),否則從小到大輸出所有可能的弧度(均四捨五入至小數點後5位,如果有兩個解四捨五入至小數點後5位後相同,只視爲一個解),中間用一個空格分隔。

示例1

輸入

複製

4
45 56 78
32 78 55
33 33 25
12 25 25

輸出

複製

0.93196 1.53271
1.24254 1.50973
NO SOLUTION.
1.25456 1.43951

備註:

1≤T≤200,
0 < x ≤ 10000
0 < y ≤ 10000
0 < v ≤ 20000
#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;
const double g=9.8;
int t;
double x,y,v,a,b,c,tan1,tan2,jg1,jg2,pd;
int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%lf%lf%lf", &x, &y, &v);
        a=-(g*x*x)/(2.0*v*v);
        b=x;
        c=-y-(g*x*x)/(2.0*v*v);
        pd=b*b-a*c*4.0;
        if (pd>0){
            tan1=(-b+sqrt(pd))/(2.0*a);
            tan2=(-b-sqrt(pd))/(2.0*a);
            jg1=atan(tan1);
            jg2=atan(tan2);
            printf("%.5lf %.5lf\n", jg1, jg2);
        }
        else if(pd<0)
			printf("NO SOLUTION.\n");
        else 
			printf("%.5lf\n", jg1);
    }
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章