Ads Proposal
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 1063 Accepted Submission(s): 410
Problem Description
There are N customers set their M different advertisements on Baidu. Each advertisement is owned by single customer. The ads system of Baidu records the number of clicks of each advertisement this year. The proposal system wants to analysis the advertisements about the relativity of the description length and the number of clicks of the advertisements. During the analysis, it is very important to do such a query to ask the total length of the advertisements with top k clicking times for each customer. You may assume the number of clicks of all advertisements are distinct. Your task is to help Baidu to design this little toolkit.
Input
The input consist multiple test cases. The number of test cases is given in the first line of the input. For each test case, the first line contains three integers N, M and Q, denoting the number customer, the number of advertisement instances and the number of queries. (N <= 100000, M <= 500000, Q <= 100000) Then M lines follow, each line contains three numbers, U, C and L, indicating the owner of this advertisement, the clicks for this advertisement and the length. (1 <= U <= N, 0 <= C, L <= 1000000000) Finally Q lines come. Each line contains only one integer k, representing the query for top k clicking advertisements for each customer.
Output
For each test case, output Q lines, each line contains only one integer, denoting the sum of total length of the top k number of clicks for each customer.
Sample Input
2 2 4 3 1 12 13 2 23 41 1 21 46 1 22 31 1 2 3 6 15 3 5 2677139 731358928 2 347112028 239095183 6 27407970 85994789 6 767687908 734935764 6 255454855 110193353 3 39860954 813158671 5 617524049 55413590 3 338773814 7907652 6 810348880 736644178 2 777664288 63811422 6 590330120 616490361 5 552407488 136492190 1 416295130 448298060 5 811513162 232437061 4 43273262 874901209 4 9 13
Sample Output
Case #1: 72 118 131 Case #2: 5801137622 5887132411 5887132411
Source
Recommend
lcy
思路很好想,但是感觉会超时,优化下就OK了。。。暂时没有想到更好的办法了
#include<stdio.h> #include<algorithm> #include<iostream> #include<stdlib.h> #include<string.h> using namespace std; const int MAXN=100005; const int MAXM=500005; int U[MAXM],C[MAXM],L[MAXM]; int rank[MAXM]; int hash[MAXN]; long long res[MAXM]; int cmp(const void *a,const void *b) { return C[*(int *)b]-C[*(int *)a]; } int main() { //freopen("test.in","r",stdin); //freopen("test.out","w",stdout); int T; int iCase; int i; iCase=0; scanf("%d",&T); int N,M,Q; int k; while(T--) { iCase++; scanf("%d%d%d",&N,&M,&Q); for(i=0;i<M;i++) { scanf("%d%d%d",&U[i],&C[i],&L[i]); rank[i]=i; } memset(hash,0,sizeof(hash)); memset(res,0,sizeof(res)); qsort(rank,M,sizeof(rank[0]),cmp); for(i=0;i<M;i++) { res[++hash[U[rank[i]]]]+=L[rank[i]]; } for(i=1;i<=M;i++) res[i]+=res[i-1]; printf("Case #%d:\n",iCase); while(Q--) { scanf("%d",&k); if(k>=M) printf("%I64d\n",res[M]); else printf("%I64d\n",res[k]); } } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/10/04/2198898.html
Hexadecimal View Time Limit: 2 Seconds Memory Limit: 65536 KB
Hexadecimal is very important and useful for computer programmers. You are requested to provide a hexadecimal view for given data. The hexadecimal view is made up of one or more rows. Every row except the last one represents 16 characters. Each row consists of three columns separated by a space:
- addr: the 4-digit hexadecimal beginning address of this row.
- dump: the hexadecimal representation of this row, separating every two characters by a whitespace. If there are less than 16 characters in the last row, pad it with spaces.
- text: the ASCII translation of this row, with uppercase characters converted to lowercase and lowercase characters converted to uppercase.
Use lowercase for the letter digits. See sample for more details.
Input
There are multiple test cases. Each line is a test case. The line is made up of no less than 1 and no more than 4096 printable characters including spaces.
Output
For each test case, output its hexadecimal view. Do not output any extra spaces after the last character of text.
Sample Input
Hex Dump
#include <cstdio>
printf("Hello, World!\n");
main = do getLine >>= print . sum . map read . words
Sample Output
0000: 4865 7820 4475 6d70 hEX dUMP
0000: 2369 6e63 6c75 6465 203c 6373 7464 696f #INCLUDE <CSTDIO
0010: 3e >
0000: 7072 696e 7466 2822 4865 6c6c 6f2c 2057 PRINTF("hELLO, w
0010: 6f72 6c64 215c 6e22 293b ORLD!\N");
0000: 6d61 696e 203d 2064 6f20 6765 744c 696e MAIN = DO GETlIN
0010: 6520 3e3e 3d20 7072 696e 7420 2e20 7375 E >>= PRINT . SU
0020: 6d20 2e20 6d61 7020 7265 6164 202e 2077 M . MAP READ . W
0030: 6f72 6473 ORDS
Author: WU, Zejun
题目比较简单,输入输出注意点。。。
看来要去复习下C++的输入输出的函数了。。。。。
WR了好多次,原来数组太小。题目给的是4096的,我卡的太紧了,,,下次开大点了。。。
C语言的函数轻松过掉
#include<stdio.h> #include<iostream> #include<string.h> #include<iomanip> using namespace std; char str[5000]; int main() { int t=0; int len; while(cin.getline(str,4100))//这里要开大点,错了好几次了 { t=0; len=strlen(str); for(t=0;t<len;t+=16) { printf("%04x: ",t); for(int i=t;i<t+16;i+=2) { if(i<len) printf("%02x",str[i]); else printf(" "); if(i+1<len) printf("%02x ",str[i+1]); else printf(" "); } for(int i=t;i<t+16&&i<len;i++) { if(str[i]>='a'&&str[i]<='z') printf("%c",str[i]-'a'+'A'); else if(str[i]>='A'&&str[i]<='Z') printf("%c",str[i]-'A'+'a'); else printf("%c",str[i]); } printf("\n"); } } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/10/02/2197977.html
Counting Game
There are n people standing in a line, playing a famous game called ``counting". When the game begins, the leftmost person says ``1" loudly, then the second person (people are numbered 1 to n from left to right) says ``2" loudly. This is followed by the 3rd person saying ``3" and the 4th person say ``4", and so on. When the n-th person (i.e. the rightmost person) said ``n" loudly, the next turn goes to his immediate left person (i.e. the (n - 1)-th person), who should say ``n + 1" loudly, then the (n - 2)-th person should say ``n + 2" loudly. After the leftmost person spoke again, the counting goes right again.
There is a catch, though (otherwise, the game would be very boring!): if a person should say a number who is a multiple of 7, or its decimal representation contains the digit 7, he should clap instead! The following tables shows us the counting process for n = 4(`X' represents a clap). When the 3rd person claps for the 4th time, he's actually counting 35.
Person |
1 |
2 |
3 |
4 |
3 |
2 |
1 |
2 |
3 |
Action |
1 |
2 |
3 |
4 |
5 |
6 |
X |
8 |
9 |
Person |
4 |
3 |
2 |
1 |
2 |
3 |
4 |
3 |
2 |
Action |
10 |
11 |
12 |
13 |
X |
15 |
16 |
X |
18 |
Person |
1 |
2 |
3 |
4 |
3 |
2 |
1 |
2 |
3 |
Action |
19 |
20 |
X |
22 |
23 |
24 |
25 |
26 |
X |
Person |
4 |
3 |
2 |
1 |
2 |
3 |
4 |
3 |
2 |
Action |
X |
29 |
30 |
31 |
32 |
33 |
34 |
X |
36 |
Given n, m and k, your task is to find out, when the m-th person claps for the k-th time, what is the actual number being counted.
There will be at most 10 test cases in the input. Each test case contains three integers n, m and k (
2n100,
1mn,
1k100) in a single line. The last test case is followed by a line with n = m = k = 0, which should not be processed.
For each line, print the actual number being counted, when the m-th person claps for the k-th time. If this can never happen, print `-1'.
4 3 1
4 3 2
4 3 3
4 3 4
0 0 0
17
21
27
35
The Seventh Hunan Collegiate Programming Contest Problemsetter: Rujia Liu, Special Thanks: Yiming Li & Jane Alam Jan
#include<stdio.h> #include<string.h> bool aa[1000000]; bool solve(int n) { if(n%7==0) return true; int t=n; while(t) { if(t%10==7) return true; t/=10; } return false; } void calc() { for(int i=1;i<1000000;i++) { if(solve(i)) aa[i]=true; else aa[i]=false; } } int main() { int n,m,k; int t; int cnt; calc(); while(scanf("%d%d%d",&n,&m,&k)!=EOF) { if(n==0&&m==0&&k==0) break; t=m; cnt=0; while(1) { if(aa[t])cnt++; if(cnt==k) { printf("%d\n",t); break; } if(n==m) { t+=2*(m-1); continue; } if(m==1) { t+=2*(n-m); continue; } t+=2*(n-m); if(aa[t])cnt++; if(cnt==k) { printf("%d\n",t); break; } t+=2*(m-1); } } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/09/17/2179752.html
One-Two-Three
Your little brother has just learnt to write one, two and three, in English. He has written a lot of those words in a paper, your task is to recognize them. Note that your little brother is only a child, so he may make small mistakes: for each word, there might be at most one wrong letter. The word length is always correct. It is guaranteed that each letter he wrote is in lower-case, and each word he wrote has a unique interpretation.
The first line contains the number of words that your little brother has written. Each of the following lines contains a single word with all letters in lower-case. The words satisfy the constraints above: at most one letter might be wrong, but the word length is always correct. There will be at most 10 words in the input.
For each test case, print the numerical value of the word.
3
owe
too
theee
1
2
3
The Seventh Hunan Collegiate Programming Contest Problemsetter: Rujia Liu, Special Thanks: Yiming Li & Jane Alam Jan
#include<stdio.h> #include<string.h> int main() { int n; char str[10]; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",&str); int len=strlen(str); if(len>3) printf("3\n"); else { if((str[0]=='o'&&str[1]=='n')||(str[0]=='o'&&str[2]=='e')||(str[1]=='n'&&str[2]=='e')) printf("1\n"); else printf("2\n"); } } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/09/17/2179734.html
字符串替换
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 5975 |
|
Accepted: 2795 |
Description
编写一个C程序实现将字符串中的所有"you"替换成"we"
Input
输入包含多行数据
每行数据是一个字符串,长度不超过1000 数据以EOF结束
Output
对于输入的每一行,输出替换后的字符串
Sample Input
you are what you do
Sample Output
we are what we do
Source
#include<stdio.h> #include<string.h> #include<iostream> using namespace std; char str[1010]; int main() { int i; int len; while(cin.getline(str,1010)) { len=strlen(str); for(i=0;i<len;i++) { if(i+2<len&&str[i]=='y'&&str[i+1]=='o'&&str[i+2]=='u') { printf("we"); i+=2; continue; } printf("%c",str[i]); } printf("\n"); } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/09/15/2178107.html
开学以来,各种忙碌,好久没有刷题了。。。。今天在POJ刷了题,,,很简单
分数加减法
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 8389 |
|
Accepted: 2668 |
Description
编写一个C程序,实现两个分数的加减法
Input
输入包含多行数据 每行数据是一个字符串,格式是"a/boc/d"。
其中a, b, c, d是一个0-9的整数。o是运算符"+"或者"-"。
数据以EOF结束 输入数据保证合法
Output
对于输入数据的每一行输出两个分数的运算结果。 注意结果应符合书写习惯,没有多余的符号、分子、分母,并且化简至最简分数
Sample Input
1/8+3/8
1/4-1/2
1/3-1/3
Sample Output
1/2
-1/4
0
Source
#include<stdio.h> int gcd(int a,int b) { if(b==0) return a; return gcd(b,a%b); } int lcm(int a,int b) { int c=gcd(a,b); return a*b/c; } int main() { int a,b,c,d; char ch; while(scanf("%d/%d%c%d/%d",&a,&b,&ch,&c,&d)!=EOF) { int m=lcm(b,d); int n; if(ch=='+') n=a*(m/b)+c*(m/d); else n=a*(m/b)-c*(m/d); if(n==0) printf("0\n"); else { int t=gcd(m,n); n=n/t;m=m/t; if(m<0) m=-m,n=-n; if(m==1) printf("%d\n",n); else printf("%d/%d\n",n,m); } } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/09/15/2178096.html
Regular Polygon
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 682 Accepted Submission(s): 174
Problem Description
In a 2_D plane, there is a point strictly in a regular polygon with N sides. If you are given the distances between it and N vertexes of the regular polygon, can you calculate the length of reguler polygon's side? The distance is defined as dist(A, B) = sqrt( (Ax-Bx)*(Ax-Bx) + (Ay-By)*(Ay-By) ). And the distances are given counterclockwise.
Input
First a integer T (T≤ 50), indicates the number of test cases. Every test case begins with a integer N (3 ≤ N ≤ 100), which is the number of regular polygon's sides. In the second line are N float numbers, indicate the distance between the point and N vertexes of the regular polygon. All the distances are between (0, 10000), not inclusive.
Output
For the ith case, output one line “Case k: ” at first. Then for every test case, if there is such a regular polygon exist, output the side's length rounded to three digits after the decimal point, otherwise output “impossible”.
Sample Input
2
3
3.0 4.0 5.0
3
1.0 2.0 3.0
Sample Output
Case 1: 6.766
Case 2: impossible
Source
Recommend
lcy
二分求解:
#include<stdio.h> #include<iostream> #include<math.h> using namespace std; const double eps=1e-10; double m[110][2]; int n; const double PI=acos(-1.0);
int jug(double mid) { double sum=0.0; int i; double temp; for(i=0;i<n;i++) { if(mid>(m[i][0]+m[i][1])-eps) return 1; if(mid<fabs(m[i][0]-m[i][1])+eps) return -1; temp=(m[i][0]*m[i][0]+m[i][1]*m[i][1]-mid*mid)/(2.0*m[i][0]*m[i][1]); sum+=acos(temp); } if(sum>PI*2.0+eps) return 1; if(sum<PI*2.0-eps) return -1; else return 0; } int main() { int i,T; int iCase=0; scanf("%d",&T); double l,r,temp; while(T--) { iCase++; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%lf",&m[i][1]); m[i+1][0]=m[i][1]; } m[0][0]=m[n][0]; bool flag=false; double mid; int temp1; l=0; r=20000; while((r-l)>eps) { mid=(r+l)/2; temp1=jug(mid); if(temp1==0) { flag=true; break; } if(temp1<0) l=mid; else r=mid; } if(!flag) printf("Case %d: impossible\n",iCase); else printf("Case %d: %.3lf\n",iCase,mid); } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/09/11/2173825.html
N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24579 Accepted Submission(s): 6774
Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
Sample Output
Author
JGShining(极光炫影)
#include<stdio.h> #include<string.h> const int MAXN=40000;//如果是10000的阶乘,改为40000就够了 int f[MAXN]; int main() { int i,j,n; while(scanf("%d",&n)!=EOF) { memset(f,0,sizeof(f)); f[0]=1; for(i=2;i<=n;i++) { int c=0; for(j=0;j<MAXN;j++) { int s=f[j]*i+c; f[j]=s%10; c=s/10; } } for(j=MAXN-1;j>=0;j--) if(f[j]) break;//忽略前导0 for(i=j;i>=0;i--) printf("%d",f[i]); printf("\n"); } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/09/09/2172795.html
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4004
本文作者 :kuangbin @SHU
博客:www.cnblogs.com/kuangbin
题意:一条长为l的河上有n个石头,告诉每个石头的位置,一个青蛙从头跳,求最少每次跳多少距离才能跳到对面。最多跳m次
解题策略:二分答案。。。其实二分的效率是很高的噢~~~~很常用的算法。。
直接贴代码了:
/*HDU 4004 二分 */ #include<stdio.h> #include<algorithm> using namespace std; #define MAXN 500010 const int INF=0x7ffffff; int d[MAXN]; int L; int calc(int x)//这个函数是计算对于跳跃能力是x的青蛙,最少跳几次过河 { int now=0; int cnt=0; int ps=0; while(now<L) { now+=x; while(now>=d[ps+1]) ps++; now=d[ps]; cnt++; } return cnt; } int main() { int n,m; int left,right,mid; int minx;//两个石头间的最大距离,就是青蛙最小的跳的能力 while(scanf("%d%d%d",&L,&n,&m)!=EOF) { minx=0; for(int i=1;i<=n;i++) scanf("%d",&d[i]); sort(d+1,d+n+1); d[0]=0; d[n+1]=L; d[n+2]=INF; for(int i=1;i<=n+1;i++) if(minx<d[i]-d[i-1]) minx=d[i]-d[i-1]; left=minx;right=L; int res; while(left<=right) { mid=(right+left)>>1; if(calc(mid)<=m) { res=mid; right=mid-1; } else left=mid+1; } printf("%d\n",res); } return 0; }
文章来源: http://www.cnblogs.com/kuangbin/archive/2011/09/03/2165907.html
Power Network
Time Limit: 2000MS |
|
Memory Limit: 32768K |
Total Submissions: 15399 |
|
Accepted: 8201 |
Description
A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amount s(u) >= 0 of power, may produce an amount 0 <= p(u) <= p max(u) of power, may consume an amount 0 <= c(u) <= min(s(u),c max(u)) of power, and may deliver an amount d(u)=s(u)+p(u)-c(u) of power. The following restrictions apply: c(u)=0 for any power station, p(u)=0 for any consumer, and p(u)=c(u)=0 for any dispatcher. There is at most one power transport line (u,v) from a node u to a node v in the net; it transports an amount 0 <= l(u,v) <= l max(u,v) of power delivered by u to v. Let Con=Σ uc(u) be the power consumed in the net. The problem is to compute the maximum value of Con.
An example is in figure 1. The label x/y of power station u shows that p(u)=x and p max(u)=y. The label x/y of consumer u shows that c(u)=x and c max(u)=y. The label x/y of power transport line (u,v) shows that l(u,v)=x and l max(u,v)=y. The power consumed is Con=6. Notice that there are other possible states of the network but the value of Con cannot exceed 6.
Input
There are several data sets in the input. Each data set encodes a power network. It starts with four integers: 0 <= n <= 100 (nodes), 0 <= np <= n (power stations), 0 <= nc <= n (consumers), and 0 <= m <= n^2 (power transport lines). Follow m data triplets (u,v)z, where u and v are node identifiers (starting from 0) and 0 <= z <= 1000 is the value of lmax(u,v). Follow np doublets (u)z, where u is the identifier of a power station and 0 <= z <= 10000 is the value of pmax(u). The data set ends with nc doublets (u)z, where u is the identifier of a consumer and 0 <= z <= 10000 is the value of cmax(u). All input numbers are integers. Except the (u,v)z triplets and the (u)z doublets, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and are correct.
Output
For each data set from the input, the program prints on the standard output the maximum amount of power that can be consumed in the corresponding network. Each result has an integral value and is printed from the beginning of a separate line.
Sample Input 2 1 1 2 (0,1)20 (1,0)10 (0)15 (1)20
7 2 3 13 (0,0)1 (0,1)2 (0,2)5 (1,0)1 (1,2)8 (2,3)1 (2,4)7
(3,5)2 (3,6)5 (4,2)7 (4,3)5 (4,5)1 (6,0)5
(0)5 (1)2 (3)2 (4)1 (5)4
Sample Output 15
6
Hint
The sample input contains two data sets. The first data set encodes a network with 2 nodes, power station 0 with pmax(0)=15 and consumer 1 with cmax(1)=20, and 2 power transport lines with lmax(0,1)=20 and lmax(1,0)=10. The maximum value of Con is 15. The second data set encodes the network from figure 1.
Source
Southeastern Europe 2003题目链接:http://poj.org/problem?id=1459
writed by kuangbin 转载请注明出处
直接套用最大流的模板的,主要是建图的过程。
输入分别为m个点,a个发电站,b个用户,n条边;接下去是n条边的信息(u,v)cost,cost表示边(u,v)的最大流量;a个发电站的信息(u)cost,cost表示发电站u能提供的最大流量;b个用户的信息(v)cost,cost表示每个用户v能接受的最大流量。 典型的最大网络流中多源多汇的问题,在图中添加1个源点S和汇点T,将S和每个发电站相连,边的权值是发电站能提供的最大流量;将每个用户和T相连,边的权值是每个用户能接受的最大流量。从而转化成了一般的最大网络流问题,然后求解。
具体看程序吧,不解释.
/**//* POJ 1459 */ #include<stdio.h> #include<iostream> #include<string.h> #include<queue> using namespace std; const int MAXN=110; const int INF=0x7fffffff; int map[MAXN][MAXN],path[MAXN],flow[MAXN],start,end; int n;//点的个数 queue<int>q; int bfs() { int i,t; while(!q.empty()) q.pop();//清空队列 memset(path,-1,sizeof(path)); path[start]=0; flow[start]=INF; q.push(start); while(!q.empty()) { t=q.front(); q.pop(); if(t==end) break; for(i=0;i<=n;i++) { if(i!=start&&path[i]==-1&&map[t][i]) { flow[i]=flow[t]<map[t][i]?flow[t]:map[t][i]; q.push(i); path[i]=t; } } } if(path[end]==-1) return -1; return flow[n]; } int Edmonds_Karp() { int max_flow=0,step,now,pre; while((step=bfs())!=-1) { max_flow+=step; now=end; while(now!=start) { pre=path[now]; map[pre][now]-=step; map[now][pre]+=step; now=pre; } } return max_flow; } int main() { int i,u,v,z,np,nc,m; while(scanf("%d%d%d%d",&n,&np,&nc,&m)!=EOF) { memset(map,0,sizeof(map)); while(m--) { while(getchar()!='('); scanf("%d,%d)%d",&u,&v,&z); u++;v++; map[u][v]=z; } while(np--) { while(getchar()!='('); scanf("%d)%d",&u,&z); u++; map[0][u]=z; } while(nc--) { while(getchar()!='('); scanf("%d)%d",&u,&z); u++; map[u][n+1]=z; } n++; start=0;end=n; printf("%d\n",Edmonds_Karp()); } return 0; }
Contact us
|
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
公告
导航
统计
- 随笔: 100
- 文章: 0
- 评论: 2
- 引用: 0
常用链接
留言簿
随笔分类
随笔档案
博客
搜索
最新评论
阅读排行榜
评论排行榜
|
|