Time Limit: 1000 MS Memory Limit: 32768 KB
*------------* |............| |............| |............| |............| |............| |............| |............| |............| |............| |............| *------------*
*------------* |............| |............| |............| |............| |------------| |------------| |------------| |------------| |------------| |------------| *------------*
2 0 60
Case #1: *------------* |............| |............| |............| |............| |............| |............| |............| |............| |............| |............| *------------* Case #2: *------------* |............| |............| |............| |............| |------------| |------------| |------------| |------------| |------------| |------------| *------------*
题解:图形输出,模拟电池。简单题83Min1Y.
代码:
#include <iostream> #include <stdio.h> using namespace std; char b[2][20]={"|............|","|------------|"}; char c[20]={"*------------*"}; int main() { int t,a; cin>>t; int k=0; while(t--) { k++; cin>>a; printf("Case #%d:\n",k); int bb=a/10; cout<<c<<endl; for(int i=1;i<=10-bb;i++) { cout<<b[0]<<endl; } for(int i=10-bb;i<10;i++) { cout<<b[1]<<endl; } cout<<c<<endl; } }
G - I Wanna Go Home POJ 3767
Time Limit: 1000 MS Memory Limit: 65536 KB
Description
The country is facing a terrible civil war----cities in the country are divided into two parts supporting different leaders. As a merchant, Mr. M does not pay attention to politics but he actually knows the severe situation, and your task is to help him reach home as soon as possible.
"For the sake of safety,", said Mr.M, "your route should contain at most 1 road which connects two cities of different camp."
Would you please tell Mr. M at least how long will it take to reach his sweet home?
Input
The input contains multiple test cases.
The first line of each case is an integer N (2<=N<=600), representing the number of cities in the country.
The second line contains one integer M (0<=M<=10000), which is the number of roads.
The following M lines are the information of the roads. Each line contains three integers A, B and T, which means the road between city A and city B will cost time T. T is in the range of [1,500].
Next part contains N integers, which are either 1 or 2. The i-th integer shows the supporting leader of city i.
To simplify the problem, we assume that Mr. M starts from city 1 and his target is city 2. City 1 always supports leader 1 while city 2 is at the same side of leader 2.
Note that all roads are bidirectional and there is at most 1 road between two cities.
Input is ended with a case of N=0.
Output
For each test case, output one integer representing the minimum time to reach home.
If it is impossible to reach home according to Mr. M's demands, output -1 instead.
Sample Input
2 1 1 2 100 1 2 3 3 1 2 100 1 3 40 2 3 50 1 2 1 5 5 3 1 200 5 3 150 2 5 160 4 3 170 4 2 170 1 2 2 2 1 0Sample Output
100 90 540 题意:N个城市M条路,后M行为城市ab之间有路,花费为c,最后一行为每个城市隶属的势力,另外,至多只能走一条连接不同势力的路(L)。问从城市1到城市2的最小花费。题解:因为默认城市1,2属于不同的势力,所以L只能是从势力1到势力2的路,然后dij跑一下就好了.133Min1Y代码:#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int INF=100000; int a,b; int c[605]; int d[605]; int map[605][605]; int vis[605]; int dij() { int v; for(int i=1;i<=a;i++) d[i]=map[1][i]; d[1]=0; vis[1]=1; for(int i=1;i<a;i++) { int mi=INF; v=1; for(int j=1;j<=a;j++) { if(!vis[j]&&mi>d[j]) { mi=d[j]; v=j; } } vis[v]=1; if(v==2) break; for(int j=1;j<=a;j++) { if(!vis[j]&&d[j]>d[v]+map[v][j]) { d[j]=d[v]+map[v][j]; } } } if(d[2]>=INF) return -1; else return d[2]; } int main() { while(cin>>a) { if(a==0) break; for(int i=1;i<=a;i++) { for(int j=1;j<=a;j++) { map[i][j]=map[j][i]=INF; } } memset(c,0,sizeof(c)); memset(vis,0,sizeof(vis)); cin>>b; int b1,b2,b3; for(int i=0;i<b;i++) { cin>>b1>>b2>>b3; map[b1][b2]=b3; map[b2][b1]=b3; } for(int i=1;i<=a;i++) { cin>>c[i]; } for(int i=1;i<=a;++i) { for(int j=1;j<=a;++j)//将这种从势力2到势力1的路设为无穷大。 { if(c[i]!=c[j]) { if(c[i]==1) map[j][i]=INF; else map[i][j]=INF; } } } cout<<dij()<<endl; } }I - Difference Between Primes HDU 4715
Time Limit: 1000 MS Memory Limit: 32768 KB
Description
All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even integer can be expressed as the difference of two primes. To validate this conjecture, you are asked to write a program.Input
The first line of input is a number nidentified the count of test cases(n<10^5). There is a even number xat the next nlines. The absolute value of xis not greater than 10^6.Output
For each number xtested, outputstwo primes aand bat one line separatedwith one space where a-b=x. If more than one group can meet it, output the minimum group. If no primes can satisfy it, output 'FAIL'.Sample Input
3 6 10 20Sample Output
11 5 13 3 23 3题意:在素数中找到差为x的数a和b,并且a得是满足这种情况的最大值。156Min2Y。题解:打一个素数表。用set存,从小到大枚举b,则a=b+x,判断a在不在set内代码:#include<stdio.h> #include <set> #include <iostream> using namespace std; int a[2000001]= {1,1}; set<int>b; int bb[153000]; int main() { int i,j,k=0; for(i=2; i<=2000000; i++) { if(!a[i]) { b.insert(i); bb[k++]=i; for(j=2; i*j<=2000000; j++) { a[i*j]=1; } } } int x,y,t,n; scanf("%d",&t); while(t--) { int flag=0; scanf("%d",&n); for(x=0; x<153000; x++) { int t=bb[x]+n; if(b.count(t)) { printf("%d %d\n",t,bb[x]); flag=1; break; } } if(!flag) cout<<"FAIL"<<endl; } return 0; }