概述
我从前最怕旁人火眼金睛,如今,倒是盼着有人能够洞幽烛远。如此,就能赠我一点欢喜。
链接:https://ac.nowcoder.com/acm/problem/14624
来源:牛客网
题目描述
Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and it is inadvertently caught in the peach blossom trap.
Fortunately, it has got a map of peach blossom trap. You can think of it as a matrix of R row and C column. ‘.’ stand for the road you can walk. ‘*’ means there is a peach tree planted in this grid, and obviously you can’t go into it.
The pig can only walk up to four adjacent squares in the upper, lower, left and right directions at a time. The outside of the matrix is the paradise of freedom, and of course, it may never go out.
Though it has got the map, but doesn't know where it is in the peach blossom trap now, that means it could be at any ‘.’ in the matrix. It finds you smart to tell it the probability it can get out of peach blossom trap, please tell him the answer in the form of p/q.
输入描述:
Multiple groups of test case. (no more than 100 groups. ) The first line of each group contains two numbers R and C,(0<=R, C<=1000), representing the number of rows and the number of columns of peach blossom trap, respectively. Stop the program when R and C are both 0. Then there are next R lines, each line contains C characters, either '.' or '*'. It is guarantee at least one grid is'. '.
输出描述:
For each test case, output the answer in the form of p/q on each line. Notice that p/q must be the fraction in lowest terms.
示例1
输入
复制
5 5 *..*. **.** *.*.* *...* ***** 3 3 *** *.* *** 0 0
输出
复制
4/9 0/1
说明
In the first sample, the number of grids the pig may appear is 9 , of which there are 4 grids it can escape from the trap, so the answer is 4/9.
#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 0x3f3f3f3f
#define P pair<int,int>
typedef long long ll;
using namespace std;
const ll MOD=1e9+7;
const int dir[][2]={{-1,0},{0,1},{1,0},{0,-1}};
char mp[1010][1010];
int n,m,fz,fm;
bool check(int x, int y) {
return !(x<0||x>=n||y<0||y>=m);
}
void dfs(int x, int y) {
if(mp[x][y]=='*')
return;
mp[x][y]='*';
fz++;
for(int i=0; i<4; i++) {
int tx=x+dir[i][0];
int ty=y+dir[i][1];
if(check(tx,ty)&&mp[tx][ty]=='.')
dfs(tx, ty);
}
}
int main(){
while(scanf("%d%d", &n, &m), n|m) {
fz=0,fm=0;
for(int i=0; i<n; i++) {
scanf("%s", mp[i]);
for(int j=0; j<m; j++)
fm+=mp[i][j]=='.';
}
for(int i=0; i<n; i++) {
if(mp[i][0]=='.')
dfs(i, 0);
if(mp[i][m-1]=='.')
dfs(i, m - 1);
}
for(int i=0; i<m; i++) {
if(mp[0][i]=='.')
dfs(0, i);
if(mp[n-1][i]=='.')
dfs(n-1, i);
}
int t=__gcd(fz, fm);
printf("%d/%dn", fz/t, fm/t);
}
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/14661
来源:牛客网
题目描述
栗酱有一天在网上冲浪的时候发现了一道很有意思的数据结构题。
该数据结构形如长条形。
一开始该容器为空,有以下七种操作。
1 a从前面插入元素a
2 从前面删除一个元素
3 a从后面插入一个元素
4 从后面删除一个元素
5 将整个容器头尾翻转
6 输出个数和所有元素
7 对所有元素进行从小到大排序
输入描述:
只有一组数据,第一行n≤50000,m≤200000, a≤100000 代表最大数据数目和操作次数。 接下来每一行一个操作如上描述。保证所有操作合法(不会在容器为空时删除元素)。 6、7操作共计不会超过10次。
输出描述:
当执行6操作时,第一行先输出当前的个数,然后从头到尾按顺序输出,每两个元素之间用一个空格隔开,末尾不能有空格。
示例1
输入
复制
10 9 1 1 3 5 3 4 6 4 5 6 7 6
输出
复制
3 1 5 4 2 5 1 2 1 5
#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 0x3f3f3f3f
#define P pair<int,int>
typedef long long ll;
using namespace std;
const ll MOD=1e9+7;
int n,m,x,t;
vector<int> aa;
int main()
{
cin>>n>>m;
for(int i=0; i<m; i++)
{
cin>>x;
if(x==1)
{
cin>>t;
aa.insert(aa.begin(), t);
}
else if(x==2)
aa.erase(aa.begin());
else if(x==3)
{
cin>>t;
aa.push_back(t);
}
else if(x==4)
aa.pop_back();
else if(x==5)
reverse(aa.begin(), aa.end());
else if(x==6)
{
cout<<aa.size()<<endl;
for (int j=0; j<aa.size(); j++)
cout<<aa[j]<<' ';
printf("n");
}
else
sort(aa.begin(), aa.end());
}
return 0;
}
链接:https://ac.nowcoder.com/acm/problem/14668
来源:牛客网
题目描述
????????????与????????????在玩一个游戏,????????????有????张卡片,每张卡片上写了一个数字,其中第????张卡片上的数字为????????。????????????说出了一个质数????,并指出可以将????张卡片重新排列使得相邻两张卡片上数字的乘积是????2 的倍数,即重新排列后满足???????? × ????????+1 ???????????? ????2 = 0(???? < ????)。???????????? 对此表示怀疑,并与????????????打赌,输的人会受到相应的惩罚。
????????????欣然接受了他的挑战,他想知道自己能否赢得这次赌注。
输入描述:
输入第一行为一个整数????(1 ≤ ???? ≤ 20),表示一共有????组测试数据。
对于每组测试数据:
第一行有两个整数????(2 ≤ ???? ≤ 104)和????(1 ≤ ???? ≤ 105),表示卡片总数与????????????提到的的质数。
第二行有????个整数,其中第????个数字????????(1 ≤ ???????? ≤ 105)代表了第????张卡片上的字母。
数据保证????是一个质数。
输出描述:
对于每组测试数据,输出如果dfd能够赢得这次赌注输出“YES”,否则输出“NO”。
示例1
输入
复制
2 5 2 4 4 1 1 1 5 3 3 3 2 2 2
输出
复制
YES NO
说明
对于第一组样例,卡片重新排列成1 4 1 4 1便能够满足要求。 对于第二组样例,不论怎么排序都无法满足要求。
#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 0x3f3f3f3f
#define P pair<int,int>
typedef long long ll;
using namespace std;
const ll MOD=1e9+7;
int pc[3],t,n,p,ct,num;
int main()
{
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&p);
memset(pc,0,sizeof(pc));
for(int i=0;i<n;i++){
ct=0;
scanf("%d",&num);
int tmp=num;
while(!(tmp%p)){
ct++;
tmp/=p;
}
if(ct>1)
pc[2]++;
if(ct==1)
pc[1]++;
if(!ct)
pc[0]++;
}
if(pc[2]>=pc[0]||(pc[2]==pc[0]-1&&!pc[1]))
printf("YESn");
else
printf("NOn");
}
return 0;
}
最后
以上就是热心鱼为你收集整理的牛客每日练习----Piglet treasure hunt Series 1,简单的数据结构,新卡片游戏我从前最怕旁人火眼金睛,如今,倒是盼着有人能够洞幽烛远。如此,就能赠我一点欢喜。的全部内容,希望文章能够帮你解决牛客每日练习----Piglet treasure hunt Series 1,简单的数据结构,新卡片游戏我从前最怕旁人火眼金睛,如今,倒是盼着有人能够洞幽烛远。如此,就能赠我一点欢喜。所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复