欢迎来到千学网!
您现在的位置:首页 > 实用文 > 其他范文

POJ 题目3630 Phone List(字符串,水)

时间:2023-03-26 08:17:26 其他范文 收藏本文 下载本文

以下是小编精心整理的POJ 题目3630 Phone List(字符串,水),本文共8篇,供大家阅读参考。

POJ 题目3630 Phone List(字符串,水)

篇1:POJ 题目3630 Phone List(字符串,水)

Phone ListTime Limit:1000MSMemory Limit:65536KTotal Submissions:23729Accepted:7293

Description

Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let‘s say the phone catalogue listed these numbers:

Emergency 911Alice 97 625 999Bob 91 12 54 26

In this case, it‘s not possible to call Bob, because the central would direct your call to the emergency line as soon as you had dialled the first three digits of Bob‘s phone number. So this list would not be consistent.

Input

The first line of input gives a single integer, 1 ≤t≤ 40, the number of test cases. Each test case starts withn, the number of phone numbers, on a separate line, 1 ≤n≤ 10000. Then followsnlines with one unique phone number on each line. A phone number is a sequence of at most ten digits.

Output

For each test case, output “YES” if the list is consistent, or “NO” otherwise.

Sample Input

2391197625999911254265113123401234401234598346

Sample Output

NOYES

Source

Nordic ac代码

#include#include#include#include#define min(a,b) (a>b?b:a)struct str{ char s[20];}b[10010];int cmp(const void *a,const void *b){ return strcmp((*(struct str *)a).s,(*(struct str *)b).s);}int n;int jud{ int i,j,k; for(i=0;i

篇2:POJ 题目1753 Flip Game(DFS)

Flip GameTime Limit:1000MSMemory Limit:65536KTotal Submissions:33029Accepted:14435

Description

Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. Each round you flip 3 to 5 pieces, thus changing the color of their upper side from black to white and vice versa. The pieces to be flipped are chosen every round according to the following rules:

Choose any one of the 16 pieces.

Flip the chosen piece and also all adjacent pieces to the left, to the right, to the top, and to the bottom of the chosen piece (if there are any).

Consider the following position as an example:

bwbw

wwww

bbwb

bwwb

Here “b” denotes pieces lying their black side up and “w” denotes pieces lying their white side up. If we choose to flip the 1st piece from the 3rd row (this choice is shown at the picture), then the field will become:

bwbw

bwww

wwwb

wwwb

The goal of the game is to flip either all pieces white side up or all pieces black side up. You are to write a program that will search for the minimum number of rounds needed to achieve this goal.

Input

The input consists of 4 lines with 4 characters “w” or “b” each that denote game field position.

Output

Write to the output file a single integer number - the minimum number of rounds needed to achieve the goal of the game from the given position. If the goal is initially achieved, then write 0. If it's impossible to achieve the goal, then write the word “Impossible” (without quotes).

Sample Input

bwwbbbwbbwwbbwww

Sample Output

4

Source

Northeastern Europe

ac代码

#include#includeint map[10][10],step,flag=0;int dx[5]={0,0,0,-1,1};int dy[5]={1,-1,0,0,0};int jud(){ int i,j; for(i=1;i<=4;i++) for(j=1;j<=4;j++) { if(map[i][j]!=map[1][1]) return 0; } return 1;}void fun(int x,int y){ int i,j; for(i=0;i<5;i++) { int fx=x+dx[i]; int fy=y+dy[i]; map[fx][fy]=!map[fx][fy]; }}void dfs(int x,int y,int cnt){ if(cnt==step) { flag=jud(); return; } if(flag) return; if(x==5) return; fun(x,y); if(y<4) dfs(x,y+1,cnt+1); else dfs(x+1,1,cnt+1); fun(x,y); if(y<4) dfs(x,y+1,cnt); else dfs(x+1,1,cnt);}int main(){ int i,j; char c; for(i=1;i<=4;i++) { for(j=1;j<=4;j++) { scanf(“%c”,&c); if(c=='b') map[i][j]=1; } getchar(); } for(step=0;step<=16;step++) { dfs(1,1,0); if(flag) break; } if(flag) printf(“%d\n”,step); else printf(“Impossible\n”);}

篇3:POJ 题目1986 Distance Queries(LCA 离线)

Distance QueriesTime Limit:2000MSMemory Limit:30000KTotal Submissions:10142Accepted:3575Case Time Limit:1000MS

Description

Farmer John's cows refused to run in his marathon since he chose a path much too long for their leisurely lifestyle. He therefore wants to find a path of a more reasonable length. The input to this problem consists of the same input as in “Navigation Nightmare”,followed by a line containing a single integer K, followed by K “distance queries”. Each distance query is a line of input containing two integers, giving the numbers of two farms between which FJ is interested in computing distance (measured in the length of the roads along the path between the two farms). Please answer FJ's distance queries as quickly as possible!

Input

* Lines 1..1+M: Same format as “Navigation Nightmare”

* Line 2+M: A single integer, K. 1 <= K <= 10,000

* Lines 3+M..2+M+K: Each line corresponds to a distance query and contains the indices of two farms.

Output

* Lines 1..K: For each distance query, output on a single line an integer giving the appropriate distance.

Sample Input

7 61 6 13 E6 3 9 E3 5 7 S4 1 3 N2 4 20 W4 7 2 S31 61 42 6

Sample Output

13336

Hint

Farms 2 and 6 are 20+3+13=36 apart.

Source

USACO February

求树上两个点最近距离

ac代码

#include#include#includestruct s{ int u,v,w,next;}edge[100100];struct que{ int u,v,num,next;}q[100010];int head1[100100],head2[100010],cnt1,cnt2,dis[100100],pre[100100],n,m,qq,vis[100100],ans[100100 ];int find(int x){ if(x==pre[x]) return x; return find(pre[x]);}void init{ memset(head1,-1,sizeof(head1)); memset(head2,-1,sizeof(head2)); memset(dis,0,sizeof(dis)); memset(vis,0,sizeof(vis)); cnt1=cnt2=0;}void add1(int u,int v,int w){ edge[cnt1].u=u; edge[cnt1].v=v; edge[cnt1].w=w; edge[cnt1].next=head1[u]; head1[u]=cnt1++;}void add2(int u,int v,int i){ q[cnt2].u=u; q[cnt2].v=v; q[cnt2].num=i; q[cnt2].next=head2[u]; head2[u]=cnt2++;}void tarjan(int u,int len){ int i,v; pre[u]=u; dis[u]=len; vis[u]=1; for(i=head2[u];i!=-1;i=q[i].next) { if(vis[q[i].v]) ans[q[i].num]=dis[u]+dis[q[i].v]-2*dis[find(q[i].v)]; } for(i=head1[u];i!=-1;i=edge[i].next) { v=edge[i].v; if(!vis[v]) { tarjan(v,len+edge[i].w); pre[v]=u; } }}int main(){ while(scanf(“%d%d”,&n,&m)!=EOF) { init(); while(m--) { int a,b,c; char str[2]; scanf(“%d%d%d%s”,&a,&b,&c,str); add1(a,b,c); add1(b,a,c); } scanf(“%d”,&qq); int i; for(i=1;i<=qq;i++) { int a,b; scanf(“%d%d”,&a,&b); add2(a,b,i); add2(b,a,i); } tarjan(1,0); // int i; for(i=1;i<=qq;i++) { printf(“%d\n”,ans[i]); } }}

篇4:POJ 题目1286 Necklace of Beads(Polya定理)

Necklace of BeadsTime Limit:1000MSMemory Limit:10000KTotal Submissions:7061Accepted:2942

Description

Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

Input

The input has several lines, and each line contains the input data n.

-1 denotes the end of the input file.

Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.

Sample Input

45-1

Sample Output

2139

Source

Xi'an

题目大意:

n个珠子串成一个圆,用三种颜色去涂色,

POJ 题目1286 Necklace of Beads(Polya定理)

问一共有多少种不同的涂色方法。

不同的涂色方法被定义为:如果这种涂色情况翻转,旋转不与其他情况相同就为不同。

解题思路:

Polya定理模版题。

对于顺时针长度为i的旋转,为pow(3,__gcd(n,i);

对于翻转,当为奇数时,有:n*pow(3.0,n/2+1);

当为偶数时,有:n/2*pow(3.0,n/2)+n/2*pow(3.0,n/2+1);

一共有2*n种情况,最后要除以2*n

ac代码

#include#include#includeint gcd(int a,int b){ if(a

篇5:《世界水日》及阅读题目和答案

《世界水日》及阅读题目和答案

世界水日

3月22日是“世界水日”。这是第47届联合国大会根据联合国环境与发展大会在《21世纪行动议程》中所提出的建议而确定的,旨在使全世界都关心解决淡水资源短缺日益严重的问题。

我们人类居住的`地球表面,约百分之七十被海洋覆盖,淡水只有百分之二左右。而在所有淡水中,百分之八十七又储存于两极冰川与永久性“雪盖”中,人类难以利用。因此,全世界可利用的淡水资源非常有限,而这少得可怜的淡水资源中有一些是已遭到污染的“脏水”。随着世界人口的迅猛增加,人类过度开采和严重浪费,工业污染等,使得淡水资源越来越短缺。由于缺水,一些国家江河干涸,农作物枯萎,牲畜断水,甚至在一些国家和地区间爆发“水战”。

“世界水日”呼唤地球儿女,要珍惜每一滴水。

我国已被列入贫水国家名单。尽管我们在水的兴利除弊方面取得了举世瞩目的成就,但与现代化建设的需要仍不相称。开发利用保护水利资源和节约用水,必须引起社会各方面的关注和支持。

阅读练习:

4.人类为什么还缺水?请你说出3个原因。

(1)_______________________________

(2)_______________________________

(3)_______________________________

参考答案:

1.覆盖 枯萎 举世瞩目

2.兴和除 利和弊 里应外合 南辕北辙 天罗地网

3.清澈见底 波光粼粼

4.人们平时污染;浪费水而使水大量缺少;危害到人们的生命。

5.做法一:邻里之间互相监督,看到有人浪费水,罚款50元。

做法二:给人们讲一个关于“水缺乏”的讲座,让人们意识到浪费水的危害,从而自觉地保护水资源。

篇6:以水之美为题目作文

以水之美为题目作文

水有千姿百态,豪放婉约无一不可,故有千万种美,今吾只在此选摘其三种以赞之。

水之美,在于“大江东去”的豪放。

江水,浩浩荡荡,一泻千里,汹涌澎湃,怒涛浊浪,既有“唯见长江天际流”的豪情万丈,又有“不尽长江滚滚来”的势不可挡,既有“湛湛长江水”的稍显悲凉,又有“长江不肯向西流”的固执倔强。纵是那叱咤风云的人物,在“尽日不分天水色”的水之力当中,也不过是微小的蝼蚁。

水之美,在于“水光潋艳晴方好”的婉约。

湖,柔顺隽永,凝波翠柳,淡雅妆美,既有“接天莲叶无穷碧”的清雅翠色,又有“月点波心一颗珠”的.美轮美奂,既有“花满苏堤柳满烟”的红妆素裹,更有“一色湖光万顷秋”的柔波万千,多少古人将湖喻为佳人,是啊,一个是生命之美,一个是自然之美,故才能有:“欲把西湖比西子”的绝佳诗文,才能造就一个又一个的诗文大家。

水之美,在于“黄河入海流”的宽容。

海,无涯无际,浩翰无边,既有“黄河入海流”的宽广心胸,又有百川东到海的一视同仁,既有“水何澹澹”江一般的豪放,又有“海日生残夜”湖一般的婉约,他包容着“曾经沧海难为水”的悲欢离合,包容着“心望海波平”的复国情怀,包容着“海内存知己”的依依惜别,包容着“江海寄余生”的壮志难酬“茫茫海波连天”,这正是包容所赐予的力量,只有像海这样,不分大小,不分贵贱,不厌恶脏的水流,不嫌弃小的水滴,来者不拒,来者不惧,把握住每一丝水汽,才能拥有海一般的力量。

水有千姿百态,千万种美,而我最欣赏的就是这三美,时而豪放,时而婉约,但最可贵的就是宽容,也只有宽容,才成就了水之美。

篇7:五水共治征文题目:携手治水,还美丽家园作文

水是生产之基,生态之要,生命之源,因此,我们要认识得到进一步提升,点滴感受,附于纸面。

污水,又脏又臭,来源于企业的非法排放,药物污染和人们的不良行为、习惯造成的后果。曾经清澈见底的小河不见了,整天嬉戏鱼虾吓跑了,就连小朋友们都对小河的记忆淡忘了;曾经甘甜可口的泉水变味了;曾经忙碌的海鸥累垮了,它们再也不回来了……治理污水,不容错过。作为地球村的一员,我们不能熟视无睹,袖手旁观,应该担负起重任,让

洪水,来势凶猛的魔头,势不可挡。它无恶不作,它吞噬农田,冲塌桥梁,冲毁房屋,

篇8:五水共治征文题目:携手治水,还美丽家园作文

五水共治征文题目:携手治水,还美丽家园作文

水是生产之基,生态之要,生命之源。因此,我们要认识得到进一步提升,点滴感受,附于纸面。

污水,又脏又臭,来源于企业的非法排放,药物污染和人们的不良行为、习惯造成的后果。曾经清澈见底的小河不见了,整天嬉戏鱼虾吓跑了,就连小朋友们都对小河的记忆淡忘了;曾经甘甜可口的泉水变味了;曾经忙碌的海鸥累垮了,它们再也不回来了……治理污水,不容错过。作为地球村的一员,我们不能熟视无睹,袖手旁观,应该担负起重任,让家乡的'天更蓝,水更绿,生机勃勃。

洪水,来势凶猛的魔头,势不可挡。它无恶不作,它吞噬农田,冲塌桥梁,冲毁房屋。多少农田秋收无粮,多少人行动不便,多少百姓无家可归,甚至一命呜呼。这些不能怪老天爷啊!这都是人类造成的啊!这都是报应啊!所以在生活中,我们应该做些力所能及的小事。劝告大人们不再乱砍乱伐,破坏植被。反之多植树造林,防止水土流失。作为大自然的一份子,我们要保护生态平衡。

涝水,危害生产,生活中的积水。在城市,在乡村,涝水不排臭气熏天,更大的危害必接踵而来。黑臭河的形成,河道不通,排水不便是一大原因。消除涝水,消除水坑,打通断水河,对于联通河网,畅通水系,提升水质起到明显作用,同时还可以提高防洪排涝能力,优化沿岸人民居住环境。

供水,节水……

我相信,只要大家团结起来,共同治水,那么,我们身边的水就会越来越干净,环境会越来越好。到处都有丰富的水源,再也没有旱灾、水灾,小鱼、小虾、小螃蟹都回来了,小河里又是一片生机盎然……让我们行动起来,为家乡的天更蓝,水更绿,做一份贡献吧!

按字节截取字符串

POJ 1704Georgia and Bob(阶梯博弈)

PHP截取中文字符串方法总结

党课题目

毕业论文题目

随笔题目

论文题目

笔试题目

心得体会题目

读后感题目

《POJ 题目3630 Phone List(字符串,水)(共8篇).doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式

点击下载本文文档