the number the starsof和a num...

Returns the number of fields in a result set
sqlite_num_fields
SQLiteResult-&numFields
SQLiteUnbuffered-&numFields
SQLiteUnbuffered->numFields — Returns the number of fields in a result set
int sqlite_num_fields
( resource $result
Object oriented style (method):
SQLiteResult
int numFields
SQLiteUnbuffered
int numFields
Returns the number of fields in the result
The SQLite result resource.
This parameter is not required when using
the object-oriented method.当前位置:
>>>The word “day” has two meanings. When we talk about the num..
The word “day” has two meanings. When we talk about the number of days in a year, we are using “day” to mean 24 hours. But when we talk about day and night, we are using “day” to mean the time between sunrise and sunset. Since the earth looks like a ball, the sun can shine on only half of it at a time. Always one half of the earth is having day and the other half night. A place is moved from day into night and from night into day over and over by the spinning(旋转) of the earth. At the equator(赤道) day and night are sometimes the same length. They are each twelve hours long. The sun rises at 6 in the morning and sets at 6 in the evening. For six months the North Pole is tilted(倾斜) toward the sun. In those months the Northern Hemisphere(半球) gets more hours of sunlight than the Southern Hemisphere. Days are longer than nights. South of the equator nights are longer than days. For the other six months the North Pole is tilted away from the sun. Then the Southern Hemisphere gets more sunlight. Days are longer than night. North of the equator nights are longer than days. Winter is the season of long nights. Summer is the season of long days.小题1:When the Western Hemisphere is having day, the Eastern Hemisphere is having ______.A.both day and nightB.day C.neither day nor night D.night小题2:A place is moved from day into night and from night into day over and over by ______ of the earth.A.the pushingB.the pullingC.the spinningD.the passing小题3:At the equator day is as long as night ______.A.sometimesB.neverC.usuallyD.always小题4:When the North Pole is tilted toward the sun, the Northern Hemisphere gets _____ sunlight.A.lessB.more C.allD.no小题5:When it is winter in China, ______.A.the USA is tilted toward the sunB.the South Pole is tilted away from the sunC.the North Pole is tilted toward the sunD.the North Pole is tilted away from the sun
题型:阅读理解难度:中档来源:不详
小题1:D小题1:C小题1:A小题1:B小题1:D略
马上分享给同学
据魔方格专家权威分析,试题“The word “day” has two meanings. When we talk about the num..”主要考查你对&&政治经济类阅读,历史文化类阅读&&等考点的理解。关于这些考点的“档案”如下:
现在没空?点击收藏,以后再看。
因为篇幅有限,只列出部分考点,详细请访问。
政治经济类阅读历史文化类阅读
政治经济类文章的概念:
要做好这类阅读,平时就要注意了解国内外发生的政治经济大事,掌握一定背景知识,对这类文章的叙述特点及内容安排有一定了解,还要扩展这方面的词汇。阅读这类文章,要抓住文章的核心,即文章整体和各段主要在说什么,也要注意段落之间的逻辑关系。如何备考政治经济类阅读理解题:
【题型说明】政治经济类阅读文章是高考常选材料之一。该类文章时代气息浓郁,语言鲜活,但熟字新义词、超纲词及专业词语多,长句、难句多。政治类文章大多数是同学们感性趣的内容,读起来倒有似曾相识的感觉,经济类文章读起来就像是雾里看花,文章看完,一头雾水。再加之这类文章的命题侧重于词义猜测、推理判断和文章主旨,同学们对这类题材是望而生畏。 【备考策略】建立心理优势。针对不同体裁的文章,我们要采取相应的阅读方法和技巧。政治类文章多采用记叙文形式,我们可采取“顺读法”,以便抓关键语句,领会文章主旨;而经济类文章则多采用说明文形式,我们则可以采取“逆读法”,先读试题,再从文章中查找有用信息。若遇到的确难读的材料。千万不用着急,因为你觉得难,其他人也一定是同感。在高考前,我们就要有这种心理准备,高考试卷肯定有一、两篇难以阅读的材料。不过,我们平时可以有意识地从报刊杂志上找一些较难的阅读材料来阅读,以培养自己迎难而上的心理素质。 【答题方法】 1、寻找主干:根据英语中五种基本句型结构,把句子中的主语、谓语、宾语、表语等主要成分找出来,其他成分如定语、状语、补语等则易于理解。找到了句子主干,句子的意思至少明白了一半。 2、剔除从句:在一个长句中可能会出现若干个从句,在理解时,如果把各个从句剔除出来单独理解,然后把大意拼凑起来,整个长句的意思就会明白六、七分。 3、辨别分句:一个长句如果是由几个并列、转折、递进、对比关系的分句组成,句中往往有表示这些分句关系的连接词,只要能弄清楚分句和分句之间的逻辑关系,再把各层分句的意思加以连贯,整个长句的句意基本上能跃然脑中。 4、寻找关键词:如果一个句子看完,一点句意的感觉也没有,下下策就是抓住句中的关键词,通过关键词大体弄懂这个长句的意思。 什么是历史文化类阅读:
本类题型常用的方式是夹叙夹议。叙述的目的是为了议,所以要把握其议才是主要方面。阅读这类文章,先弄清其引入的话题,再弄清里面人物对其不同的看法,然后理解作者本身对话题的观点看法或思考。 历史文化类阅读技巧:
【题型说明】历史文化类阅读理解文章属高考常选材料之一。这类文章常涉及历史、文化、法制、宗教等方面的文学艺术、发明创造、文化遗产保护、宗教与文化、风俗与习惯、道德与法制、中外文学名著节选、等等。这类材料的命题点往往落在主旨大意题、事实细节题上。 【答题方法】在做这类阅读理解题时,我们应注意以下几个方面: 1、采用先题后文:先读题目,再带着问题读文章。这类阅读理解文章相对来说事实细节题稍多一点,如果带着问题读文章,有利于我们抓细节。 2、先做细节题。因为做完了局部性的事实细节题后,自然会加深我们对文章的理解,这样更有利于做主旨大意题。 3、重点敲定主旨题。主旨大意题提问的形式主要有两大类:一类是Main idea型;一类是Topic或Title型。在解答这类试题时应注意以下几点: a.读首句抓大意。文化教育类阅读理解文章多采用说明文、议论文体裁,而这类文章大都采用文章段落的中心,即主题句在文章开头。因此,要寻找这类文章的主旨大意就需要研究文章的首句。 b.读尾句抓大意。有时这类文章的主题句安排在文章的结尾,作为对全篇的总结。 c.读首段抓大意。有些文章或段落的开头和结尾部分都有主题句。这种结构是为了突出主题思想而使用两次点题的写作方法。这两个主题句在句子结构和用词上有所不同,而且在内容上前句和后句也不重复。 d.从段落中抓大意。有些文章或段落的主题句在文章中,这种文章或段落往往以一句话或几句话引出要表达的主题,在主题句出现后,再举例子陈述细节或继续论证。 e.归纳要点抓大意。有些文章或段落无明显的主题句,只是暗示性地体现主题。这就要求同学们在阅读过程中根据文中所叙述的事实或线索来概括总结主旨大意。
发现相似题
与“The word “day” has two meanings. When we talk about the num..”考查相似的试题有:
401943402985328815389423370235440071雅思IELTS考试
出国留学考试培训
数学DS-5d1wik
The table above shows the number of students in a certain high school class who are boys and the number of students in the class who are studying biology. What is the total number of students in the class?(1)Of the boys in the class, 15 are studying biology.(2)The number of girls in the class is twice the number of students in the class who are not studying biology.
AStatement (1) ALONE is sufficient, but statement (2) alone is not sufficient.BStatement (2) ALONE is sufficient, but statement (1) alone is not sufficient.CBOTH statement TOGETHER are sufficient, but NEITHER statement ALONE is sufficient.DEACH statement ALONE is sufficient.EStatements (1) and (2) TOGETHER are NOT sufficient.正确答案:B
当前版本由angelif更新于 20:43:02
感谢由angelif用户对此题目的解答所做出的贡献。
(2)设x为 number not studying biology.2x+18=x+26
如果对题目有任何的疑惑,欢迎在这里提出来,大家会帮你解答的
这是一个提问,求回答
使用考GMAT的7大理由
1.每天2000+学生在这里学习讨论
2.OG,PREP,GWD全部题目收录
3.备考题目权威解析
4.模拟真实考试的模考系统
5.根据知识点与难度整理的练习册
6.做题数据云记录
7.强大的错题强化练习功能
最火爆、优质的GMAT备考网站
做错本题的人也做错
What is the remainder when the two-digit, positive intege...
If x and y are integers, is y an even integer?[br/](1) [m...
What is the remainder when the positive integer n is divi...
One kilogram of a certain coffee blend consists of x kilo...
If [math]x^3y^4=5000[/math], is y = 5?[br/](1) y is a pos...
最近更新题目
用户名/Email邮箱地址:
登录密码:
下次自动登录
还没有考满分的账号?
使用其它账号直接登录
合作培训机构账号激活
此服务是赠送功能,目前仅限考GMAT报名培训的考生免费使用
你当前得浏览器版本过低,无法观看视频,建议更换使用chrome浏览器获得更好的体验
练习方式:
原题,选项乱序
选项强化(仅SC和CR)
题目筛选:
最近三天最近一周
做过一次一直做错
没有符合上述条件的错题,要不,换条件试试?
最全GMAT备考资源,注册即可免费拥有!
第三方登录:
该解答共被1名用户修改了1次
版本修改时间修订人字数
20:43:02angelif64
常用标签:
请选择错误类型:
格式有错误
题目内容有错误
请描述一下这个错误:Reducing the Number of Gray Levels in an Image - monstar_hp的专栏
- 博客频道 - CSDN.NET
1123人阅读
(a) Write a computer program capable of reducing the number of gray levels in a image from 256 to 2, in integer powers of 2. The desired number of gray levels needs to be a variable input to your program.
(b) Download Fig. 2.21(a) and duplicate the results shown in Fig. 2.21 of the book.
reduceGrayLevel.m
function img = reduceGrayLevel(image, level)
imageSize = size(image);
num = 256 /
img = uint8(zeros(imageSize(1), imageSize(2)));
for r = 1:1:imageSize(1)
for c = 1:1:imageSize(2)
img(r, c) = fix(double(image(r, c)) / num) * 255 / (level-1);
proj0201.m
image = imread('Fig0221(a)(ctskull-256).tif');
img1 = reduceGrayLevel(image, 128);
img2 = reduceGrayLevel(image, 64);
img3 = reduceGrayLevel(image, 32);
img4 = reduceGrayLevel(image, 16);
img5 = reduceGrayLevel(image, 8);
img6 = reduceGrayLevel(image, 4);
img7 = reduceGrayLevel(image, 2);
subplot(2, 4, 1), imshow(image), subplot(2, 4, 2), imshow(img1), ...
subplot(2, 4, 3), imshow(img2), subplot(2, 4, 4), imshow(img3), ...
subplot(2, 4, 5), imshow(img4), subplot(2, 4, 6), imshow(img5), ...
subplot(2, 4, 7), imshow(img6), subplot(2, 4, 8), imshow(img7);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:25270次
排名:千里之外
原创:36篇
(1)(1)(1)(6)(14)(8)(1)(6)PAT 解题报告 - Rachel Zhang的专栏
- 博客频道 - CSDN.NET
5265人阅读
PAT 1070基础贪心Mooncake (25)100 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueMooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region's culture. Now given the inventory amounts and the prices of all kinds of the mooncakes, together with the maximum total demand of the market, you are supposed to tell the maximum profit that can be made.Note: partial inventory storage can be taken. The sample shows the following situation: given three kinds of mooncakes with inventory amounts being 180, 150, and 100 thousand tons, and the prices being 7.5, 7.2, and 4.5 billion yuans. If the market demand can be at most 200 thousand tons, the best we can do is to sell 150 thousand tons of the second kind of mooncake, and 50 thousand tons of the third kind. Hence the total profit is 7.2 + 4.5/2 = 9.45 (billion yuans).Input Specification:Each input file contains one test case. For each case, the first line contains 2 positive integers N (&=1000), the number of different kinds of mooncakes, and D (&=500 thousand tons), the maximum total demand of the market. Then the second line gives the positive inventory amounts (in thousand tons), and the third line gives the positive prices (in billion yuans) of N kinds of mooncakes. All the numbers in a line are separated by a space.Output Specification:For each test case, print the maximum profit (in billion yuans) in one line, accurate up to 2 decimal places.Sample Input:3 200
180 150 100
7.5 7.2 4.5
Sample Output:9.45#include &iostream&
#include &algorithm&
#include &stdio.h&
#include &stdlib.h&
#include &string.h&
#include &functional&
#include &memory.h&
#define N 1010
#define min(a,b) a&b?b:a
bool operator & (const P & A) const
return perprice&A.
int main()
int n,cap,i;
while(cin&&n&&cap)
for(i=0;i&n;i++)
cin&&Moon[i].
for(i=0;i&n;i++)
cin&&Moon[i].
for(i=0;i&n;i++)
Moon[i].perprice = Moon[i].price/Moon[i].
sort(Moon, Moon+n);
double sum = 0;
int i = 0;
while(cap&0&&i&=n)
int v = min(cap,Moon[i].cap);
sum += v*Moon[i].
printf(&%.2f\n&,sum);
}PAT 1071字符串处理+mapSpeech Patterns (25)300 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者HOU, QimingPeople often have a preference among synonyms of the same word. For example, some may prefer &the police&, while others may prefer &the cops&. Analyzing such patterns can help to narrow down a speaker's identity, which is useful when validating, for example, whether it's still the same person behind an online avatar.Now given a paragraph of text sampled from someone's speech, can you find the person's most commonly used word?Input Specification:Each input file contains one test case. For each case, there is one line of text no more than 1048576 characters in length, terminated by a carriage return '\n'. The input contains at least one alphanumerical character, i.e., one character from the set [0-9 A-Z a-z].Output Specification:For each test case, print in one line the most commonly occurring word in the input text, followed by a space and the number of times it has occurred in the input. If there are more than one such words, print the lexicographically smallest one. The word should be printed in all lower case. Here a &word& is defined as a continuous sequence of alphanumerical characters separated by non-alphanumerical characters or the line beginning/end.Note that words are case&insensitive.Sample Input:Can1: &Can a can can a can?
Sample Output:can 5
#include&iostream&
#include &string&
#include&map&
#include&algorithm&
#define N 1000
bool isalp(char a)
if(a&='a'&&a&='z'||a&='A'&&a&='Z'||a&='0'&&a&='9')
int main()
string str,
map&string,int& C//notice it's better not substitute 'string' to 'char*', for char* stores the address while string stores object
map&string,int&::iterator it,
while(getline(cin,str))
transform(str.begin(),str.end(),str.begin(),::tolower);
//cout&&str&&
int i=0,j;
while(i&str.length())
while(!isalp(str[j])&&j&str.length())j++;//skip non-alphanumerical character
while(isalp(str[j])&&i&str.length())j++; //i is the start and j is the end point
string word=str.substr(i,j-i);//notice the usage of substr: substr(start,length)
if(Count.find(word)==Count.end())
Count[word] = 1;
Count[word]++;
int minn = -1;
for(it = Count.begin();it!=Count.end();it++)
if(it-&second&minn)
minn = it-&
cout&&tmp-&first&&& &&&tmp-&second&&
}PAT 1072最短路径+sort (用到一些STL函数)Gas Station (30)200 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the houses are in its service range.Now given the map of the city and several candidate locations for the gas station, you are supposed to give the best recommendation. If there are more than one solution, output the one with the smallest average distance to all the houses. If such a solution is still not unique, output the one with the smallest index number.Input Specification:Each input file contains one test case. For each case, the first line contains 4 positive integers: N (&= 103), the to M (&= 10), the total number of the candidate locations
K (&= 104), the number of roads connecting the houses
and DS, the maximum service range of the gas station. It is hence assumed that all the houses are numbered from 1 to N, and all the candidate locations are numbered from G1 to GM.Then K lines follow, each describes a road in the formatP1 P2 Distwhere P1 and P2 are the two ends of a road which can be either house numbers or gas station numbers, and Dist is the integer length of the road.Output Specification:For each test case, print in the first line the index number of the best location. In the next line, print the minimum and the average distances between the solution and all the houses. The numbers in a line must be separated by a space and be accurate up to 1 decimal place. If the solution does not exist, simply output “No Solution”.Sample Input 1:4 3 11 5
Sample Output 1:G1
Sample Input 2:2 1 2 10
Sample Output 2:No Solution#include&iostream&
#include &string&
#include&algorithm&
#include&memory.h&
#include&numeric&
#include &stdlib.h&
#define N 1001
#define M 12
#define INF
double map[N+M][N+M];
double dist[N+M];
bool visited[N+M];
struct Gas
bool operator & (const Gas & A) const
if(A.mindis!=mindis)
return mindis&A.
if(A.averagedis!=averagedis)
return averagedis&A.
return idx&A.
int str2int(char s[],int n)
if(s[0]=='G')
int sum=i==0?0:n;
sum+=atoi(s+i);
void dijkstra(int source,int n)
memset(visited,false,sizeof(visited));
visited[source] =
for(j=1;j&=n;j++)
dist[j] = map[j][source];
dist[source] = 0;
for(j=0;j&n-1;j++)
int minn = INF,
for(i=1;i&=n;i++)
if(!visited[i] && dist[i]&minn)
minn = dist[i];
visited[point] =
for(i=1;i&=n;i++)
if(!visited[i]&&dist[i]&dist[point]+map[point][i])
dist[i] = dist[point]+map[point][i];
int main()
int n,m,k,r;
cin&&n&&m&&k&&r;
char str1[5],str2[5];
for(i=1;i&=n+m;i++)
for(j=1;j&=n+m;j++)
map[i][j] = map[j][i] =
while(k--)
scanf(&%s%s%lf&,str1,str2,&dis);
int a = str2int(str1,n);
int b = str2int(str2,n);
map[a][b] = map[b][a] =
int n_avaliable = 0;
for(i=1;i&=m;i++)
int source = n+i;
dijkstra(source,n+m);
for(j=1;j&=n;j++)
if(dist[j]&r)
if(j==n+1)
G[n_avaliable].idx =
G[n_avaliable].mindis = *min_element(dist+1,dist+n+1);
G[n_avaliable].averagedis = accumulate(dist+1,dist+n+1,0);
n_avaliable++;
if(n_avaliable == 0)
cout&&&No Solution&&&
sort(G,G+n_avaliable); //actually we needn't to sort. However, it won't cost much for little m&=10 in this case.
cout&&&G&&&G[0].idx&&
printf(&%.1f %.1f\n&,G[0].mindis,G[0].averagedis/n);
}PAT 1061字符串处理(注意边界)1061. Dating (20)50 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueSherlock Holmes received a note with some strange strings: &Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm&. It took him only a minute to figure out that those strange strings are actually referring to the coded time &Thursday 14:04& -- since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter 'D', representing the 4 the second common character is the 5th capital letter 'E', representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is 's' at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.Input Specification:Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.Output Specification:For each test case, print the decoded time in one line, in the format &DAY HH:MM&, where &DAY& is a 3-character abbreviation for the days in a week -- that is, &MON& for Monday, &TUE& for Tuesday, &WED& for Wednesday, &THU& for Thursday, &FRI& for Friday, &SAT& for Saturday, and &SUN& for Sunday. It is guaranteed that the result is unique for each case.Sample Input:3485djDkxh4hhGE
2984akDfkkkkggEdsb
Sample Output:THU 14:04
#include&iostream&
#include&string&
#define min(a,b) a&b?a:b
int main()
string str[5];
string day[8] = {&MON&,&TUE&,&WED&,&THU&,&FRI&,&SAT&,&SUN&};
for(i=0;i&4;i++)
cin&&str[i];
for(i=0;i&min(str[0].length(),str[1].length());i++)
if(str[0][i]==str[1][i]&&str[0][i]&='A'&&str[0][i]&='G')//notice it is 'G' not 'Z'
int d=str[0][i]-'A';
for(;i&min(str[0].length(),str[1].length());i++)
if(str[0][i]==str[1][i]&&(str[0][i]&='A'&&str[0][i]&='N'||str[0][i]&='0'&&str[0][i]&='9'))
int h = str[0][i]&'9'?str[0][i]-'A'+10:str[0][i]-'0';
for(i=0;i&min(str[2].length(),str[3].length());i++)
if(str[2][i]==str[3][i]&&(str[2][i]&='a'&&str[2][i]&='z'||str[2][i]&='A'&&str[2][i]&='Z'))
cout&&day[d]&&& &;
printf(&%02d:%02d\n&,h,i);
}PAT 1062排序1062. Talent and Virtue (25)200 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, LiAbout 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a &sage(圣人)&; being less excellent but with one's virtue outweighs talent can be called a &nobleman(君子)&; being good in neither is a &fool man(愚人)&; yet a fool man is better than a &small man(小人)& who prefers talent than virtue.Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.Input Specification:Each input file contains one test case. Each case first gives 3 positive integers in a line: N (&=105), the total number of L (&=60), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this and H (&100), the higher line of qualification -- that is, those with both grades not below this line are considered as the &sages&, and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the &noblemen&, and are also ranked in non-increasing order according to their total grades, but they are listed after the &sages&. Those with both grades below H, but with virtue not lower than talent are considered as the &fool men&. They are ranked in the same way but after the &noblemen&. The rest of people whose grades both pass the L line are ranked after the &fool men&.Then N lines follow, each gives the information of a person in the format:ID_Number Virtue_Grade Talent_Grade
where ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.Output Specification:The first line of output must give M (&=N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.Sample Input:14 60 80
Sample Output:12
90#include&iostream&
#include&string&
#include&functional&
#include&algorithm&
#define min(a,b) a&b?a:b
#define N 100001
struct Peo
bool operator &(Peo const & A)const
if(level!=A.level)
return level&A.
if(total!=A.total)
return total&A.
if(v!=A.v)
return v&A.v;
pare(A.id)&0;
int main()
int n,l,h;
int a,b,level,idx = 0;
cin&&n&&l&&h;
while(n--)
scanf(&%d%d&,&a,&b);
if(a&=l&&b&=l)
if(a&=h&&b&=h)
level = 4;
else if(a&=h&&b&h)
level = 3;
else if(a&h && b&h && a&=b)
level = 2;
level = 1;
P[idx].v =
P[idx].h =
P[idx].total = a+b;
P[idx].id=
P[idx++].level =
cout&&idx&&
sort(P,P+idx);
for(int i = 0;i&i++)
cout&&P[i].
printf(& %d %d\n&,P[i].v,P[i].h);
}PAT 1063大数据优化处理(容易超时)注意点:1. 50个数组,2000次询问:存结果(见代码中percent数组)2. 排序,从O(n^2)降到O(nlogn)1063. Set Similarity (25)300 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueGiven two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc&is the number of distinct common numbers shared by the two sets, and Nt&is the total number of distinct numbers in the two sets. Your job is to calculate the similarity of any given pair of sets.Input Specification:Each input file contains one test case. Each case first gives a positive integer N (&=50) which is the total number of sets. Then N lines follow, each gives a set with a positive M (&=104) and followed by M integers in the range [0, 109]. After the input of sets, a positive integer K (&=2000) is given, followed by K lines of queries. Each query gives a pair of set numbers (the sets are numbered from 1 to N). All the numbers in a line are separated by a space.Output Specification:For each query, print in one line the similarity of the sets, in the percentage form accurate up to 1 decimal place.Sample Input:3
3 99 87 101
4 87 101 5 87
7 99 101 18 5 135 18 99
Sample Output:50.0%
33.3%#include&iostream&
#include&string&
#include&vector&
#include&functional&
#include&algorithm&
#define min(a,b) a&b?a:b
#define N 10001
#define M 51
double percent[M][M];//save the asking result (for faster)
int main()
int n,tmp,ax,bx,
vector&int& a[51],
scanf(&%d&,&n);
for(j=0;j&n;j++)
vec.clear();
scanf(&%d&,&nx);
for(i = 0;i&i++)
scanf(&%d&,&tmp);
if(find(vec.begin(),vec.end(),tmp)==vec.end())
vec.push_back(tmp);
sort(vec.begin(),vec.end());
for(i=0;i&n;i++)
for(j=0;j&n;j++)
percent[i][j]=-1;
while(n--)
scanf(&%d%d&,&ax,&bx);
ax--;bx--;
if(percent[ax][bx]!=-1)
printf(&%.1f%%\n&,percent[ax][bx]);
int same=0,distinct=a[ax].size();
int ia=0,ib=0;
int la=a[ax].size(), lb = a[bx].size();
while(ia&la && ib&lb)
while(a[ax][ia]&a[bx][ib]&&ia&la)
while(a[bx][ib]&a[ax][ia]&&ib&lb)
distinct++;
if(a[ax][ia]==a[bx][ib])
ia++,ib++;
while(ib&lb)
distinct++;
double perc = 1.0*same/distinct*100.0;
percent[ax][bx]=percent[bx][ax]=
printf(&%.1f%%\n&,perc);
}PAT 1064完全二叉树+层次遍历(典型递归)输入数组从小到大的顺序为“左根右”遍历顺序,因此按前序遍历依次赋值即可。1064. Complete Binary Search Tree (30)100 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node's key.The right subtree of a node contains only nodes with keys greater than or equal to the node's key.Both the left and right subtrees must also be binary search trees.A Complete Binary Tree (CBT) is a tree that is completely filled, with the possible exception of the bottom level, which is filled from left to right.Now given a sequence of distinct non-negative integer keys, a unique BST can be constructed if it is required that the tree must also be a CBT. You are supposed to output the level order traversal sequence of this BST.Input Specification:Each input file contains one test case. For each case, the first line contains a positive integer N (&=1000). Then N distinct non-negative integer keys are given in the next line. All the numbers in a line are separated by a space and are no greater than 2000.Output Specification:For each test case, print in one line the level order traversal sequence of the corresponding complete binary search tree. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line.Sample Input:10
1 2 3 4 5 6 7 8 9 0
Sample Output:6 3 8 1 5 7 9 0 2 4#include&iostream&
#include&string&
#include&vector&
#include&functional&
#include&algorithm&
#define N 1001
int a[N],tree[N];
void LRR(int i,int n)//left-&root-&right sequence
int l=2*i,r=2*i+1;
//cout&&i&&
tree[i]=a[idx++];
int main()
int n,tmp,i,j;
scanf(&%d&,&n);
for(j=0;j&n;j++)
scanf(&%d&,&a[j]);
sort(a,a+n);
for(i=1;i&n;i++)
printf(&%d &,tree[i]);
printf(&%d\n&,tree[i]);
}PAT 1046小朋友们注意保存中间结果以防超时哦1046. Shortest Distance (20)100 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThe task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file contains one test case. For each case, the first line contains an integer N (in [3, 105]), followed by N integer distances D1&D2&... DN, where Di&is the distance between the i-th and the (i+1)-st exits, and DN&is between the N-th and the 1st exits. All the numbers in a line are separated by a space. The second line gives a positive integer M (&=104), with M lines follow, each contains a pair of exit numbers, provided that the exits are numbered from 1 to N. It is guaranteed that the total round trip distance is no more than 107.Output Specification:For each test case, print your results in M lines, each contains the shortest distance between the corresponding given pair of exits.Sample Input:5 1 2 4 14 9
Sample Output:3
#include&iostream&
#include&string&
#include&vector&
#include&functional&
#include&numeric&
#include&algorithm&
#define min(a,b)a&b?b:a
#define N 100009
int a[N];//part sum
int main()
int n,m,i,s,e,r,sum=0,ans,t;
scanf(&%d&,&n);
for(i=1;i&=n;i++)
scanf(&%d&,&t);
a[i+1]=a[i]+t;
sum = a[n+1];
//sum = accumulate(a,a+n,0);
scanf(&%d&,&m);
while(m--)
scanf(&%d%d&,&s,&e);
r=a[e]-a[s];
ans = min(r,sum-r);
printf(&%d\n&,ans);
}PAT 1047PAT 1048水题1048. Find Coins (25)50 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueEva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she could only use exactly two coins to pay the exact amount. Since she has as many as 105&coins with her, she definitely needs your help. You are supposed to tell her, for any given amount of money, whether or not she can find two coins to pay for it.Input Specification:Each input file contains one test case. For each case, the first line contains 2 positive numbers: N (&=105, the total number of coins) and M(&=103, the amount of money Eva has to pay). The second line contains N face values of the coins, which are all positive numbers no more than 500. All the numbers in a line are separated by a space.Output Specification:For each test case, print in one line the two face values V1&and V2&(separated by a space) such that V1&+ V2&= M and V1&&= V2. If such a solution is not unique, output the one with the smallest V1. If there is no solution, output &No Solution& instead.Sample Input 1:8 15
1 2 8 7 2 4 11 15
Sample Output 1:4 11
Sample Input 2:7 14
1 8 7 2 4 11 15
Sample Output 2:No Solution#include&iostream&
#include&string&
#include&vector&
#include&functional&
#include&memory.h&
#include&numeric&
#include&algorithm&
#define min(a,b)a&b?b:a
#define N 1001
bool a[N];//part sum
int main()
int n,m,i,tmp,l;
scanf(&%d%d&,&n,&m);
memset(a,false,sizeof(a));
int count_mid = 0;
if(m%2==1)
while(n--)
scanf(&%d&,&tmp);
while(n--)
scanf(&%d&,&tmp);
if(tmp==m/2)
count_mid++;
l=min(N/2,m/2);
for(i=1;i&=l;i++)
if(a[i]&&a[m-i] && (i*2!=m||count_mid&=2))
printf(&%d %d\n&,i,m-i);
if(i==l+1)
printf(&No Solution\n&);
}PAT 1049考虑每一位为1的个数1049. Counting Ones (30)10 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThe task is simple: given any positive integer N, you are supposed to count the total number of 1's in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1's in 1, 10, 11, and 12.Input Specification:Each input file contains one test case which gives the positive N (&=230).Output Specification:For each test case, print the number of 1's in one line.Sample Input:12
Sample Output:5#include&iostream&
#include&string&
#include&vector&
#include&functional&
#include&memory.h&
#include&vector&
#include&numeric&
#include&algorithm&
#define min(a,b)a&b?b:a
int main()
unsigned int x,left,right,b,d,sum=0;
scanf(&%u&,&x);
b = 1;//base
while(left!=0)
left = x/(b*10);
right = x %
midbit = (x/b)%10;
switch(midbit)
sum+=left*b;
sum+=left*b+right+1;
sum += (left+1)*b;
printf(&%u\n&,sum);
}PAT 1007经典——最大连续和#include&iostream&
#include&string&
#include&vector&
#include&functional&
#include&memory.h&
#include&vector&
#include&numeric&
#include&algorithm&
#define min(a,b)a&b?b:a
#define N 10010
#define INF 2&&30-1
int main()
int n,i,maxx=-INF,sum=0,s,e,start,
s=e=start=end=0;
for(i=0;i&n;i++)
scanf(&%d&,&a[i]);
sum+=a[i];
if(maxx&sum)
if(maxx==-INF)
printf(&0 %d %d\n&,a[0],a[n-1]);
printf(&%d %d %d\n&,maxx,a[start],a[end]);
}海盗分赃问题——博弈2-10. 海盗分赃400 ms内存限制32000 kB代码长度限制8000 B判题程序StandardP个海盗偷了D颗钻石后来到公海分赃,一致同意如下分赃策略:首先,P个海盗通过抽签决定1-P的序号。然后由第1号海盗提出一个分配方案(方案应给出每个海盗分得的具体数量),如果能够得到包括1号在内的绝对多数(即大于半数)同意,则按照该分配方案执行,否则1号将被投入大海喂鲨鱼;而后依次类似地由第2号、第3号等等海盗提出方案,直到能够获得绝对多数同意的方案出现为止,或者只剩下最后一位海盗,其独占所有钻石。请编写一个程序,给出第1号海盗的钻石分配方案中自己分得的钻石数量。附带的三个假定:1)
“聪明”与“贪婪”假定:每个海盗总能够以本人利益最大化作为行为准则;2)
“人性化”假定:在能够取得尽量多钻石的情况下,海盗不会故意致同伙于死地;3)
“无偏见”假定:海盗之间没有个人恩怨,分给其他海盗钻石的次序以小序号优先为原则。输入格式说明:输入2个正整数D和P(3&=P&=D&=100)。输出格式说明:输出第1号海盗的钻石分配方案中自己分得的钻石数量。样例输入与输出:序号输入输出110 7
从后往前推p个人分d个钻石的分配情况(第一个人的策略)x 0 1 2 0 1 0 1 0 1......(后面就是0,1循环了)三个人的情况:x 0 1#include&iostream&
#include&string&
#include&vector&
#include&functional&
#include&memory.h&
#include&vector&
#include&numeric&
#include&algorithm&
#define min(a,b)a&b?b:a
#define N 10010
#define INF 2&&30-1
bool f[N];//flag
int main()
int ans,p,d;
while(cin&&d&&p)
ans = d-3-(p-4)/2;
else if(p==3)
ans = d-1;
printf(&%d\n&,ans);
}1014. Waiting in Line (30)纯模拟。。给几个测试数据:2 1 10 102 10 1 514 7 1 536 511 2 11 2 3 4 5 6 7 8 9 1008:0208:1008:0316:3708:1708:1817:1425:08SorrySorry2 1 3 31 541 1241 2 308:0117:0110:052 2 7 51 2 6 4 3 534 23 4 5 6 708:0708:0608:1017:00Sorry10 2 3 31 541 31 2 308:0117:0108:03#include&iostream&
#include&memory.h&
#include &queue&
#define N 22
#define M 12
#define P 1010
#define MAXX (17-8)*60
#define min(a,b) a&b?a:b
struct Window
queue&int&
int service_//remain service time
int main()
int n,m,k,q,i,j,
scanf(&%d%d%d%d&,&n,&m,&k,&q);
for (i=0; i&k; i++)
scanf(&%d&,&a[i]);
memset(t, -1, sizeof(t));
//first m*n people
int fir = min(n*m,k);
for (i=0; i& i++) {
wid = i%n;
w[wid].customs.push(i);
for(i=0;i&n;i++)
if(w[i].customs.empty())
w[i].service_time = 0;
w[i].service_time = a[w[i].customs.front()];
i= //person id
int curtime = 0;
bool flag =
//push_back at tail
while (true) {
int minn = ;
for (j=0;j&n;j++) {
if( !w[j].customs.empty() && minn&w[j].service_time)
minn = w[j].service_
if(!w[j].customs.empty())
int wid_front = w[wid].customs.front();
curtime += w[wid].service_
t[wid_front] =
for(j=0;j&n;j++)
if(j!=wid &&!w[j].customs.empty())
w[j].service_time-=w[wid].service_
w[wid].customs.pop();
w[wid].customs.push(i);
if(!w[wid].customs.empty())
w[wid].service_time = a[w[wid].customs.front()];
for(i=0;i&q;i++)
scanf(&%d&,&tmp);
if(t[tmp]-a[tmp]&=MAXX)
printf(&Sorry\n&);
int h = t[tmp]/60 + 8;
int m = t[tmp]%60;
printf(&%02d:%02d\n&,h,m);
}开始没建立结构体,先按vector分别插入各个属性的map再排序,结果TLE。因为这样是O(M*NlogN),M是询问次数,N是book数。所以改成先排序,为O(NlogN+NM).#include&iostream&
#include&string&
#include &functional&
#include &algorithm&
#include &string.h&
#include &vector&
#define N 10010
#define K 1010
#define L 85
struct BOOK
string id,name,publisher,author,
vector&string&
bool operator & (BOOK const & A) const
return id&A.
int main()
int n,m,i,year,
char tmpc[L];
scanf(&%d&,&n);
char* split = & &;
getchar();
for(i=0;i&n;i++)
gets(tmpc); b[i].id =
gets(tmpc); b[i].name =
gets(tmpc); b[i].author =
gets(tmpc);
char *key = strtok(tmpc,split);
while (key!=NULL)
string keystr =
b[i].keys.push_back(keystr);
key = strtok(NULL,split);
gets(tmpc); b[i].publisher =
gets(tmpc); b[i].year =
sort(b,b+n);
scanf(&%d&,&m); getchar();
while (m--)
gets(tmpc);
char c = tmpc[0];
printf(&%s\n&,tmpc);
string str = (string)
str.substr(3,str.length()-3+1);
const char* sc = str.c_str();
bool flag=
switch(tmpc[0])
for(i=0;i&n;i++)
if(!b[i].pare(sc))
cout&&b[i].id&&endl,flag =
for(i=0;i&n;i++)
if(!b[i].pare(sc))
cout&&b[i].id&&endl,flag =
for(i=0;i&n;i++)
for (int j=0;j&b[i].keys.size();j++)
if(b[i].keys[j]==sc)
cout&&b[i].id&&endl,flag =
for(i=0;i&n;i++)
if(!b[i].pare(sc))
cout&&b[i].id&&endl,flag =
case '5': //input is year
for(i=0;i&n;i++)
if(!b[i].pare(sc))
cout&&b[i].id&&endl,flag =
printf(&Not Found\n&);
}恶心的大模拟。。。桌子没有空:& &如果新空出一个,可以给vip用(有vip在等)---&把最先空出的table给vip& &如果新空出一个,没有vip在等---&找出最小id的table给平民桌子有空:& &vip在等,且有vip table---&找到最小id的vip table给vip& &平民在等,或者vip在等但是没有vip table---&找到最小id的table给在等的人#include &iostream&
#include &algorithm&
#include &functional&
#include &memory.h&
#define T 101
#define INF 3600*50
#define max(a,b) a&b?b:a
bool played[N];
int table[T],nserve[T];
int v[N];//vip ids
bool usedt[T],isvipt[T];
int totaltable,n;
struct Players
bool cmp1(Players A,Players B)
inline void print(int t)
int h = t/3600;
m = (t/60)%60;
printf(&%02d:%02d:%02d &,h,m,t);
inline void Allocate(int t_id,int p_id)
if(table[t_id]&=21*3600)
played[p_id] =
print(p[p_id].come);
print(table[t_id]);
int wait = max(0,table[t_id]-p[p_id].come);
printf(&%d\n&,(wait+30)/60);
table[t_id] += p[p_id].
nserve[t_id]++;
int main()
int i,j,n_vip=0,tt,n_viptable,
char st[15];
scanf(&%d&,&n);
for (i=0;i&n;i++)
scanf(&%s%d%d&,&st,&p[i].playtime,&p[i].vip);
if(p[i].playtime&2*60)
p[i].playtime=
p[i].playtime*=60;
int h = atoi(strtok(st,&:&));
int m = atoi(strtok(NULL,&:&));
int s = atoi(strtok(NULL,&:&));
tt=s+60*(m+60*h);
p[i].come =
scanf(&%d%d&,&totaltable,&n_viptable);
memset(isvipt,false,sizeof(isvipt));
memset(nserve,0,sizeof(nserve));
for (i=0;i&n_i++)
scanf(&%d&,&tmp);tmp--;
isvipt[tmp] =
for(i=0;i&i++)
table[i] = 8*3600;
memset(usedt,false,sizeof(usedt));
sort(p,p+n,cmp1);
for(i=0;i&n;i++)
if(p[i].vip)
v[n_vip++] =
memset(played,false,sizeof(played));
int c_vip =0;
for(i=0;i&n;)
if(played[i]){
int time = p[i].
int fast = INF,table_idx,hasvipt = -1, minidx_vac = -1;
bool full =
for(j=0;j&j++)
if(table[j]&=time) // not full
if(minidx_vac==-1) //first vacate table
minidx_vac =
if(isvipt[j])
hasvipt = //first vip table
if(full && table[j]&fast) // if full
fast = table[j];
table_idx = //first table to be idle
if(c_vip&n_vip&& isvipt[table_idx] && p[v[c_vip]].come&fast) //has vip and
Allocate(table_idx,v[c_vip++]);
else // no vip or &vip has no vip table&
Allocate(table_idx,i);
if(p[i++].vip)
else // not full
if(p[i].vip) // has vip
if(hasvipt!=-1) // has vip table
table[hasvipt] = p[i].
Allocate(hasvipt,i++);
// no vip or &vip has no vip table&
table[minidx_vac] = p[i].
Allocate(minidx_vac,i++);
for(i=0;i&totaltable-1;i++)
printf(&%d &,nserve[i]);
printf(&%d\n&,nserve[i]);
//system(&pause&);
}方法:1. 按人名排好序,搜索:O(NlogN+K*N*K)2. 按人名排好序,加入课程的vector:O(NlogN+NK) -&better。代码如下:#include &iostream&
#include &string.h&
#include&stdio.h&
#include &algorithm&
#include&functional&
#include&vector&
#define N 40010
#define C 2510
int Nc[C];
vector&int& Courses[C];
struct Student
char name[5];
vector&int&
bool operator & (const Student & A)const
return strcmp(name,A.name)&0;
int main()
int n,c,i,j,
while (scanf(&%d%d&,&n,&c)!=EOF)
for (i=0;i&c;i++)
Courses[i].clear();
for (i=0;i&n;i++)
scanf(&%s%d&,&s[i].name,&j);
while(j--)
scanf(&%d&,&tmp);
Nc[tmp]++;
s[i].cour.push_back(tmp);
sort(s,s+n);
for (i=0;i&n;i++)
for (j=0;j&s[i].cour.size();j++)
Courses[s[i].cour[j]].push_back(i);
for (i=0;i&c;i++)
int cid = i+1;
printf(&%d %d\n&,cid,Nc[cid]);
for (j=0;j&Courses[cid].size();j++)
printf(&%s\n&,s[Courses[cid][j]].name);
}水题,但是为什么下面写了这么长?主要想说明char* 函数的返回!char*函数的返回形式:1. char*f (char* s) √{& & & &}2. char* f(...) ×{& & & &char s[20];& & & &}3. char* f(...) √{& & & &char *s = (char*) malloc(20);& & & &....& & & &}也就是说,只有堆内分配内存(malloc)时才可以以char*返回。当然最保险的还是。。。不写函数形式。#include &iostream&
#include &string.h&
#include&stdio.h&
#include &algorithm&
#include&functional&
#include&vector&
#include&memory.h&
#define N 11
char* dd(char* s)
char *res = (char*) malloc(22);
for (i=0;i&22;i++)
res[i]='\0';
//memset(res,'\0',sizeof(res));
res[0]='a';
int l = strlen(s),inc = 0,t;
for (i=l;i&0;i--)
t = (s[i-1]-'0')*2+
inc = t/10;
res[i] = (t%10)+'0';
res[i] = inc+'0';
int main()
char s[22];
int C2[22];
while(scanf(&%s&,s)!=EOF)
memset(C,0,sizeof(C));
for(i=0;i&strlen(s);i++)
C[s[i]-'0']++;
char *res = dd(s);
memset(C2,0,sizeof(C2));
i=res[0]=='a'?1:0;
for (;i&strlen(res);i++)
C2[res[i]-'0']++;
for (i=0;i&10;i++)
if(C[i]!=C2[i])
printf(&No\n&);
if (i==10)
printf(&Yes\n&);
if(res[0]=='a')
for (i=1;i&strlen(res);i++)
printf(&%c&,res[i]);
printf(&\n&);
printf(&%s\n&,res);
}水题。注意string的插入方式。新申请一个string,不能直接引用str[i]...用str = &&; 然后str.insert(str.begin(),c) or&str.insert(str.end(),c)&#include &iostream&
#include &string.h&
#include&string&
#include&stdio.h&
#define N 11
bool isp(string s)
int l=0,r=s.length()-1;
while (l&r)
if(s[l]!=s[r])
if(l!=r&&l!=r+1)
string add(string str)
string res = &&;
int l = str.length(),x,inc=0,i;
for ( i=l-1;i&=0;i--)
x = str[i]+str[l-1-i]-2*'0'+
inc = x/10;
res.insert(res.begin(),x%10+'0');
res.insert(res.begin(),inc+'0');
int main()
int n,k,i,j;
while(cin&&str&&k)
bool flag =
for (i=0;i&k;i++)
if(isp(str))
str = add(str);
cout&&str&&endl&&i&&
}不得不说。。。这题真是太贱了!注意点:1. 输入radix有界,但是找另一个radix的时候上界不是36,而是第一个数的value+1(很大所以要二分)2. 找radix的时候需要考虑不要超过value1,超过就break不要一直加上去了,因为radix上界很大,会越界3. 二分时候一般是m = (left+right)/2开始(非单增or单减),但是1位数在不同进制下value可能是一样的,所以最开始要从m=l开始。4. 原先用的unsigned int(4bytes),应该改用long long(8bytes)下面给出两个版本:1. 15min敲完得19分版本:#include &iostream&
#include &string.h&
#include&string&
#include&stdio.h&
#define N 11
unsigned int trans(string s, int r)
unsigned int x=0;
for (i=0;i&s.length()-1;i++)
if(isdigit(s[i]))
x+=s[i]-'0';
x+=s[i]-'a'+10;
if(isdigit(s[i]))
x+=s[i]-'0';
x+=s[i]-'a'+10;
bool impossible(string s, int r)
for (int i=0;i&s.length();i++)
if(isdigit(s[i]))
c = s[i]-'0';
else if(isalpha(s[i]))
c = s[i]-'a'+10;
bool lookfor(string s,unsigned int x)
int i,j,r,maxx='0'-1;
for(i=0;i&s.length();i++)
if(maxx&s[i])
maxx = s[i];
if(isdigit(maxx))
r = maxx-'0';
else if(isalpha(maxx))
r = maxx - 'a'+10;
for(r = r+1;r&=36;r++)
t = trans(s,r);
int main()
string a,b;
int i,j,r1,r2,flag,possible = 1;
unsigned int
while (cin&&a&&b&&flag&&r1)
if(flag==1)
if(impossible(a,r1))
cout&&&Impossible&&&
x = trans(a,r1);
if(!lookfor(b,x))
cout&&&Impossible&&&
if(impossible(b,r2))
cout&&&Impossible&&&
x = trans(b,r2);
if(!lookfor(a,x))
cout&&&Impossible&&&
}2. 90min改完完全AC版:#include &iostream&
#include &string.h&
#include&string&
#include&stdio.h&
#define N 11
int getc(char c)
if(isdigit(c))
return c-'0';
return c-'a'+10;
long long trans(string s, long long r,int mode, long long comp)
long long x=0;
int tail = getc(s[s.length()-1]);
for (i=0;i&s.length()-1;i++)
x+=getc(s[i]);
if(mode && x+tail&comp)
bool impossible(string s, long long r)
for (int i=0;i&s.length();i++)
c=getc(s[i]);
bool lookfor(string s,long long x,long long r)
int i,j,maxx='0'-1;
long long l,m,t;
for(i=0;i&s.length();i++)
if(maxx&s[i])
maxx = s[i];
l = getc(maxx)+1;
r = max(x+1,l);
while(l&=r)
t = trans(s,m,1,x);
m=(l+r)&&1;
int main()
string a,b;
int i,j,flag,possible = 1;
r1,r2,x,y;
while (cin&&a&&b&&flag&&r1)
if(flag==1)
if(impossible(a,r1))
cout&&&Impossible&&&
x = trans(a,r1,0,0);
if(!lookfor(b,x,r1))
cout&&&Impossible&&&
if(impossible(b,r2))
cout&&&Impossible&&&
x = trans(b,r2,0,0);
if(!lookfor(a,x,r2))
cout&&&Impossible&&&
}求两个升序的中数,水题。#include &iostream&
#include &string.h&
#include&algorithm&
#include &functional&
#include&string&
#include&stdio.h&
#define N 1000001
long int a1[N],a2[N], a[N*2];
int main()
int n2,n1,i,j;
while (scanf(&%d&,&n1)!=EOF)
for(i=0;i&n1;i++)
scanf(&%ld&,&a1[i]);
scanf(&%d&,&n2);
for(i=0;i&n2;i++)
scanf(&%ld&,&a2[i]);
int k=0,K = (n1+n2-1)&&1;
while (i&n1 && j&n2 && k&=K)
if(a1[i]&a2[j])
a[k++] = a1[i++];
a[k++] = a2[j++];
while(i&n1 && k&=K)
a[k++] = a1[i++];
while(j&n2 && k&=K)
a[k++] = a2[j++];
printf(&%ld\n&,a[K]);
}类似,单源有代价最短路#include &iostream&
#include &vector&
#include&string&
#include&stdio.h&
#include&memory.h&
#define N 505
#define INF 1000000
bool visited[N];
int map[N][N],cost[N][N];
int dist[N],mc[N];
int path[N];
void dijkstra(int s,int e,int n){
memset(visited,false,sizeof(visited));
visited[s] =
int i,j,minnd,minnc,
for (j=0;j&n-1;j++)
minnd = minnc = INF;
for(i=0;i&n;i++)
if(!visited[i] && (dist[i]&minnd ||dist[i]==minnd && mc[i]&minnc))
minnd = dist[i];
minnc = mc[i];
visited[point] =
if(point==e)
for(i=0;i&n;i++)
if(!visited[i]&&
(dist[i]&dist[point]+map[point][i]||
dist[i]==dist[point]+map[point][i] && mc[i]&mc[point]+cost[point][i]))
dist[i] = dist[point]+map[point][i];
mc[i]=mc[point]+cost[point][i];
int main()
int i,j,s,e,n,m,a,b,t,c;
while(scanf(&%d%d%d%d&,&n,&m,&s,&e)!=EOF)
for(i=0;i&n;i++)
dist[i] = INF;
mc[i] = INF;
for(j=0;j&n;j++)
map[i][j] = INF;
cost[i][j] = INF;
while(m--)
scanf(&%d%d%d%d&,&a,&b,&t,&c);
if(map[a][b]&t || map[a][b]==t && cost[a][b]&c)
map[a][b] = map[b][a] =
cost[a][b] = cost[b][a] =
else if(b==s)
dijkstra(s,e,n);
int point =
vector&int&
while(point!=s)
v.push_back(point);
point = path[point];
printf(&%d &,s);
while(!v.empty())
printf(&%d &,v.back());
v.pop_back();
printf(&%d %d\n&,dist[e],mc[e]);
给出所有父节点-子节点关系,求树中各层所有的叶节点个数分别用dfs建树和搜索。注意:树节点要用指针数组 Tree* child[100],对child赋地址时要新建变量(new Tree),否则地址都一样了。搜索时不用传指针,对象就可以。#include &iostream&
#include &vector&
#include&string&
#include&stdio.h&
#include&memory.h&
#define N 105
int num[N];
vector&int& child[N];
struct Tree
Tree* child[100];
//number of children
void search(Tree* tree)
int r = tree-&
tree-&nc = child[r].size();
maxlevel = max(maxlevel,tree-&level);
for (i=0;i&tree-&i++)
Tree* tmp = new T
tmp-&id = child[r][i];
tmp-&level = tree-&level+1;
tmp-&nc = child[tmp-&id].size();
tree-&child[i] =
search(tmp);
void dfs(Tree x)
num[x.level]++;
for (int i=0;i&x.i++)
dfs(*(x.child[i]));
int main()
int n,m,i,j,r,k,
scanf(&%d%d&,&n,&m);
memset(num,0,sizeof(num));
while(m--)
scanf(&%d%d&,&r,&k);
while (k--)
scanf(&%d&,&tmp);
child[r].push_back(tmp);
t.id = 1;//&01&
t.level = 0;
maxlevel = -1;
search(&t);
for (i=0;i&i++)
printf(&%d &,num[i]);
printf(&%d\n&,num[i]);
system(&pause&);
}或者可以不建树,直接用树节点id搜:#include &iostream&
#include &vector&
#include&string&
#include&stdio.h&
#include&memory.h&
#define N 105
int num[N];
vector&int& child[N];
int level[N];
void build(int cid)
maxlevel = max(maxlevel,level[cid]);
for(i=0;i&child[cid].size();i++)
level[child[cid][i]] = level[cid]+1;
build(child[cid][i]);
void dfs(int x)
if(child[x].size()==0)
num[level[x]]++;
for(i=0;i&child[x].size();i++)
dfs(child[x][i]);
int main()
int n,m,i,j,r,k,
scanf(&%d%d&,&n,&m);
memset(num,0,sizeof(num));
while(m--)
scanf(&%d%d&,&r,&k);
while (k--)
scanf(&%d&,&tmp);
child[r].push_back(tmp);
level[1] = 0;
for (i=0;i&i++)
printf(&%d &,num[i]);
printf(&%d\n&,num[i]);
system(&pause&);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2942487次
积分:31474
积分:31474
排名:第60名
原创:459篇
转载:34篇
评论:3661条
浙江大学CS硕士在读,关注计算机视觉,机器学习,算法研究,人工智能, 移动互联网等学科和产业,希望结识更多同道中人。
新浪微博:
(1)(2)(9)(1)(1)(5)(2)(1)(3)(4)(6)(6)(5)(4)(1)(1)(1)(6)(1)(2)(7)(6)(7)(11)(20)(12)(23)(29)(37)(37)(6)(24)(6)(1)(1)(2)(2)(1)(7)(23)(20)(32)(17)(5)(22)(58)(8)(8)

我要回帖

更多关于 the number 的文章

 

随机推荐