周赛(一)
2016-03-27 16:02
337 查看
A
//模拟,进制转换,水
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int main()
{
int t,n,m;
int i,j,k;
ll nn,mm;
while(scanf("%d",&t)!=EOF)
{
ll sum=0;
while(t--)
{
scanf("%d(%d)",&n,&m);
nn=0;k=0;
while(n)
{
mm=n%10;
nn+=mm*pow(m,k);
n/=10;
k++;
}
sum+=nn;
}
printf("%lld\n",sum);
}
return 0;
}
//DP
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 1010
#define M 1000000007
using namespace std;
ll dp
;
ll a
;
int main()
{
int t,n,m;
int i,j,k;
while(scanf("%d",&n),n)
{
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
scanf("%d",&a[i]),dp[i]=a[i];
dp[0]=a[0];
ll maxx=-1;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[j]<a[i])
dp[i]=max(dp[i],dp[j]+a[i]);
}
maxx=max(maxx,dp[i]);
}
printf("%lld\n",maxx);
}
return 0;
}
//二分+转换
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF -0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int a[1010];
int main()
{
int n;
int i,j;
while(scanf("%d",&n),n)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int ans=INF;
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=0;j--)
{
if(i==j)
continue;
int sum=a[i]-a[j];
int l=0,r=j-1;
while(l<r)
{
if(a[l]+a[r]==sum&&l!=j&&r!=i)
{
ans=a[i];
break;
}
if(a[l]+a[r]>sum)
r--;
else
l++;
}
if(ans!=INF)
break;
}
if(ans!=INF)
break;
}
if(ans==INF)
printf("no solution\n");
else
printf("%d\n",ans);
}
return 0;
}
//约瑟夫环+打表+找规律
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int k;
int dp[15];
bool solve(int m)
{
int cur=0;
for(int i=1;i<=k;i++)
{
if((cur+m-1)%(2*k-i+1)<k)
return false;
cur=(cur+m-1)%(2*k-i+1);
}
return true;
}
int main()
{
for(k=1;k<15;k++)
{
int i;
for(i=1;;i++)
{
if(solve(i))
break;
}
dp[k]=i;
}
while(~scanf("%d",&k),k)
{
printf("%d\n",dp[k]);
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 1010
#define M 1000000007
using namespace std;
struct zz
{
int d;
int f;
}p
;
bool cmp(zz a,zz b)
{
return a.f>b.f;
}
int a
;
int main()
{
int t,n,m;
int i,j,k;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&p[i].d);
for(i=0;i<n;i++)
scanf("%d",&p[i].f);
sort(p,p+n,cmp);
m=0;
for(i=0;i<n;i++)
{
k=0;
for(j=p[i].d;j>0;j--)
{
if(a[j]==0)
{
a[j]=1;
k=1;
break;
}
}
if(k==0)
m+=p[i].f;
}
printf("%d\n",m);
}
return 0;
}HDU
- 1709
The Balance
Submit Status
Description
Now you are asked to measure a dose of medicine with a balance and a number of weights. Certainly it is not always achievable. So you should find out the qualities which cannot be measured from the range [1,S]. S is the total quality
of all the weights.
Input
The input consists of multiple test cases, and each case begins with a single positive integer N (1<=N<=100) on a line by itself indicating the number of weights you have. Followed by N integers Ai (1<=i<=N), indicating the quality
of each weight where 1<=Ai<=100.
Output
For each input set, you should first print a line specifying the number of qualities which cannot be measured. Then print another line which consists all the irrealizable qualities if the number is not zero.
Sample Input
3
1 2 4
3
9 2 1
Sample Output
0
2
4 5
//母函数
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int a
,b
,c
,d
;
int main()
{
int t,n,m;
int i,j,k;
while(scanf("%d",&n)!=EOF)
{
int s=0;
for(i=1;i<=n;i++)
scanf("%d",&c[i]),s+=c[i];
for(i=0;i<=s;i++)
{
a[i]=0;
b[i]=0;
}
for(i=0;i<=c[1];i+=c[1])
a[i]=1;
for(i=2;i<=n;i++)
{
for(j=0;j<=s;j++)
{
for(k=0;k+j<=s&&k<=c[i];k+=c[i])
{
if(k>=j)
b[k-j]+=a[j];
else
b[j-k]+=a[j];
b[j+k]+=a[j];
}
}
for(j=0;j<=s;j++)
{
a[j]=b[j];
b[j]=0;
}
}
k=0;
for(i=0;i<=s;i++)
{
if(a[i]==0)
d[k++]=i;
}
printf("%d\n",k);
if(k)
{
for(i=0;i<k-1;i++)
printf("%d ",d[i]);
printf("%d\n",d[k-1]);
}
}
return 0;
}
//数学规律
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define ll long long
#define N 1010
#define M 1000000007
using namespace std;
double s[110];
int main()
{
int t,n,m;
int i,j,k;
s[2]=1;
for(i=4;i<=100;i+=2)
{
double ss=(i-2)*1.0/(i-1);
s[i]=s[i-2]*ss;
}
while(scanf("%d",&n)!=EOF)
{
printf("%.5lf\n",s
);
}
return 0;
}
//题意:有n头牛要去第x头牛的住处参加party。。参加完还要返回。。
先输入n,m,x;分别表示有n头牛,m条路单向,单向的,单向的路(重要的说三遍),x表示要去的终点。因为牛都比较懒,所以他们都会采取最短路的方式去和返回,现在问这n头牛中要花费最长时间的牛的时间。
//思路:
来回单向最短路,因为n的范围是(n<1000),所以用笛杰斯特拉就行了。平常我们写的都是去的,这块就要新学到点东西了,这里直接求得来回的最短路(很机智)。
HDU - 2106 decimal system
Description As we know , we always use the decimal system in our common life, even using the computer. If we want to calculate the value that 3 plus 9, we just import 3 and 9.after calculation of computer, we will get the result of 12. But after learning <<The Principle Of Computer>>,we know that the computer will do the calculation as the following steps: 1 computer change the 3 into binary formality like 11; 2 computer change the 9 into binary formality like 1001; 3 computer plus the two number and get the result 1100; 4 computer change the result into decimal formality like 12; 5 computer export the result; In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several number with a kind of change method, for example, if I give you 1011(2), it means 1011 is a number in the binary system, and 123(10) means 123 if a number in the decimal system. Now I will give you some numbers with any kind of system, you guys should tell me the sum of the number in the decimal system. Input There will be several cases. The first line of each case contains one integers N, and N means there will be N numbers to import, then there will be N numbers at the next N lines, each line contains a number with such form : X1….Xn.(Y), and 0<=Xi<Y, 1<Y<=10. I promise you that the sum will not exceed the 100000000, and there will be at most 100 cases and the 0<N<=1000. Output There is only one line output case for each input case, which is the sum of all the number. The sum must be expressed using the decimal system. Sample Input 3 1(2) 2(3) 3(4) 4 11(10) 11(2) 11(3) 11(4) Sample Output 6 23 |
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int main()
{
int t,n,m;
int i,j,k;
ll nn,mm;
while(scanf("%d",&t)!=EOF)
{
ll sum=0;
while(t--)
{
scanf("%d(%d)",&n,&m);
nn=0;k=0;
while(n)
{
mm=n%10;
nn+=mm*pow(m,k);
n/=10;
k++;
}
sum+=nn;
}
printf("%lld\n",sum);
}
return 0;
}
HDU - 1087 Super Jumping! Jumping! Jumping!
Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path. Your task is to output the maximum value according to the given chessmen list. Input Input contains multiple test cases. Each test case is described in a line as follow: N value_1 value_2 …value_N It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int. A test case starting with 0 terminates the input and this test case is not to be processed. Output For each case, print the maximum according to rules, and one line one case. Sample Input 3 1 3 2 4 1 2 3 4 4 3 3 2 10 Sample Output 4 10 3 |
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define ull unsigned long long
#define ll long long
#define IN __int64
#define N 1010
#define M 1000000007
using namespace std;
ll dp
;
ll a
;
int main()
{
int t,n,m;
int i,j,k;
while(scanf("%d",&n),n)
{
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
scanf("%d",&a[i]),dp[i]=a[i];
dp[0]=a[0];
ll maxx=-1;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[j]<a[i])
dp[i]=max(dp[i],dp[j]+a[i]);
}
maxx=max(maxx,dp[i]);
}
printf("%lld\n",maxx);
}
return 0;
}
POJ - 2549 Sumsets
Description Given S, a set of integers, find the largest d such that a + b + c = d where a, b, c, and d are distinct elements of S. Input Several S, each consisting of a line containing an integer 1 <= n <= 1000 indicating the number of elements in S, followed by the elements of S, one per line. Each element of S is a distinct integer between -536870912 and +536870911 inclusive. The last line of input contains 0. Output For each S, a single line containing d, or a single line containing "no solution". Sample Input 5 2 3 5 7 12 5 2 16 64 256 1024 0 Sample Output 12 no solution |
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF -0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int a[1010];
int main()
{
int n;
int i,j;
while(scanf("%d",&n),n)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int ans=INF;
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=0;j--)
{
if(i==j)
continue;
int sum=a[i]-a[j];
int l=0,r=j-1;
while(l<r)
{
if(a[l]+a[r]==sum&&l!=j&&r!=i)
{
ans=a[i];
break;
}
if(a[l]+a[r]>sum)
r--;
else
l++;
}
if(ans!=INF)
break;
}
if(ans!=INF)
break;
}
if(ans==INF)
printf("no solution\n");
else
printf("%d\n",ans);
}
return 0;
}
HDU - 1443 Joseph
Description The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give us the message about the incident. For example when n = 6 and m = 5 then the people will be executed in the order 5, 4, 6, 2, 3 and 1 will be saved. Suppose that there are k good guys and k bad guys. In the circle the first k are good guys and the last k bad guys. You have to determine such minimal m that all the bad guys will be executed before the first good guy. Input The input file consists of separate lines containing k. The last line in the input file contains 0. You can suppose that 0 < k < 14. Output The output file will consist of separate lines containing m corresponding to k in the input file. Sample Input 3 4 0 Sample Output 5 30 |
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int k;
int dp[15];
bool solve(int m)
{
int cur=0;
for(int i=1;i<=k;i++)
{
if((cur+m-1)%(2*k-i+1)<k)
return false;
cur=(cur+m-1)%(2*k-i+1);
}
return true;
}
int main()
{
for(k=1;k<15;k++)
{
int i;
for(i=1;;i++)
{
if(solve(i))
break;
}
dp[k]=i;
}
while(~scanf("%d",&k),k)
{
printf("%d\n",dp[k]);
}
return 0;
}
CodeForces - 618B Guess the Permutation
Description Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integeri from 1 to n. Bob gave you all the values of ai, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given. Input The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the information given. Output Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them. Sample Input Input 2 0 1 1 0 Output 2 1 Input 5 0 2 2 1 2 2 0 4 1 3 2 4 0 1 3 1 1 1 0 1 2 3 3 1 0 Output 2 5 4 1 3 Hint In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}. //模拟: #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespace std; int num[60],map[60][60],vis[1010]; int main() { int n; while(scanf("%d",&n)!=EOF) { memset(map,0,sizeof(map)); for(int i=1;i<=n;i++) { num[i]=i; memset(vis,0,sizeof(vis)); for(int j=1;j<=n;j++) { scanf("%d",&map[i][j]); vis[map[i][j]]++; } int a=0,k=0; for(int j=1;j<=n;j++) { if(vis[j]-1>a) { a=j; } } num[i]=a; } int f1=0,f2=0; for(int i=1;i<=n;i++) if(num[i]==0) { if(f1==0) num[i]=n-1,f1=i; else f2=i,num[i]=n; } for(int i=1;i<n;i++) { printf("%d ",num[i]); } printf("%d\n",num ); } return 0; } HDU - 1789 Doing Homework again
Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will reduce his score of the final test. And now we assume that doing everyone homework always takes one day. So Ignatius wants you to help him to arrange the order of doing homework to minimize the reduced score. Input The input contains several test cases. The first line of the input is a single integer T that is the number of test cases. T test cases follow. Each test case start with a positive integer N(1<=N<=1000) which indicate the number of homework.. Then 2 lines follow. The first line contains N integers that indicate the deadlines of the subjects, and the next line contains N integers that indicate the reduced scores. Output For each test case, you should output the smallest total reduced score, one line per test case. Sample Input 3 3 3 3 3 10 5 1 3 1 3 1 6 2 3 7 1 4 6 4 2 4 3 3 2 1 7 6 5 4 Sample Output 0 3 5 //模拟+贪心: |
#include<string.h>
#include<algorithm>
#include<iostream>
#define INF 0x3f3f3f3f
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 1010
#define M 1000000007
using namespace std;
struct zz
{
int d;
int f;
}p
;
bool cmp(zz a,zz b)
{
return a.f>b.f;
}
int a
;
int main()
{
int t,n,m;
int i,j,k;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&p[i].d);
for(i=0;i<n;i++)
scanf("%d",&p[i].f);
sort(p,p+n,cmp);
m=0;
for(i=0;i<n;i++)
{
k=0;
for(j=p[i].d;j>0;j--)
{
if(a[j]==0)
{
a[j]=1;
k=1;
break;
}
}
if(k==0)
m+=p[i].f;
}
printf("%d\n",m);
}
return 0;
}HDU
- 1709
The Balance
Time Limit: 1000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
Now you are asked to measure a dose of medicine with a balance and a number of weights. Certainly it is not always achievable. So you should find out the qualities which cannot be measured from the range [1,S]. S is the total quality
of all the weights.
Input
The input consists of multiple test cases, and each case begins with a single positive integer N (1<=N<=100) on a line by itself indicating the number of weights you have. Followed by N integers Ai (1<=i<=N), indicating the quality
of each weight where 1<=Ai<=100.
Output
For each input set, you should first print a line specifying the number of qualities which cannot be measured. Then print another line which consists all the irrealizable qualities if the number is not zero.
Sample Input
3
1 2 4
3
9 2 1
Sample Output
0
2
4 5
//母函数
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define IN __int64
#define ull unsigned long long
#define ll long long
#define N 10010
#define M 1000000007
using namespace std;
int a
,b
,c
,d
;
int main()
{
int t,n,m;
int i,j,k;
while(scanf("%d",&n)!=EOF)
{
int s=0;
for(i=1;i<=n;i++)
scanf("%d",&c[i]),s+=c[i];
for(i=0;i<=s;i++)
{
a[i]=0;
b[i]=0;
}
for(i=0;i<=c[1];i+=c[1])
a[i]=1;
for(i=2;i<=n;i++)
{
for(j=0;j<=s;j++)
{
for(k=0;k+j<=s&&k<=c[i];k+=c[i])
{
if(k>=j)
b[k-j]+=a[j];
else
b[j-k]+=a[j];
b[j+k]+=a[j];
}
}
for(j=0;j<=s;j++)
{
a[j]=b[j];
b[j]=0;
}
}
k=0;
for(i=0;i<=s;i++)
{
if(a[i]==0)
d[k++]=i;
}
printf("%d\n",k);
if(k)
{
for(i=0;i<k-1;i++)
printf("%d ",d[i]);
printf("%d\n",d[k-1]);
}
}
return 0;
}
HDU - 2407 Knots
Description An even number N of strands are stuck through a wall. On one side of the wall, a girl ties N/2 knots between disjoint pairs of strands. On the other side of the wall, the girl's groom-to-be also ties N/2 knots between disjoint pairs of strands. You are to find the probability that the knotted strands form one big loop (in which case the couple will be allowed to marry). For example, suppose that N = 4 and you number the strands 1, 2, 3, 4. Also suppose that the girl has created the following pairs of strands by tying knots: {(1, 4), (2,3)}. Then the groom-to-be has two choices for tying the knots on his side: {(1,2), {3,4)} or {(1,3), (2,4)}. Input The input file consists of one or more lines. Each line of the input file contains a positive even integer, less than or equal to 100. This integer represents the number of strands in the wall. Output For each line of input, the program will produce exactly one line of output: the probability that the knotted strands form one big loop, given the number of strands on the corresponding line of input. Print the probability to 5 decimal places. Sample Input 4 20 Sample Output 0.66667 0.28377 |
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define ll long long
#define N 1010
#define M 1000000007
using namespace std;
double s[110];
int main()
{
int t,n,m;
int i,j,k;
s[2]=1;
for(i=4;i<=100;i+=2)
{
double ss=(i-2)*1.0/(i-1);
s[i]=s[i-2]*ss;
}
while(scanf("%d",&n)!=EOF)
{
printf("%.5lf\n",s
);
}
return 0;
}
POJ - 3268 Silver Cow Party
Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse. Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow's return route might be different from her original route to the party since roads are one-way. Of all the cows, what is the longest amount of time a cow must spend walking to the party and back? Input Line 1: Three space-separated integers, respectively: N, M, and X Lines 2.. M+1: Line i+1 describes road i with three space-separated integers: Ai, Bi, and Ti. The described road runs from farm Ai to farm Bi, requiring Ti time units to traverse. Output Line 1: One integer: the maximum of time any one cow must walk. Sample Input 4 8 2 1 2 4 1 3 2 1 4 7 2 1 1 2 3 5 3 1 2 3 4 4 4 2 3 Sample Output 10 Hint Cow 4 proceeds directly to the party (3 units) and returns via farms 1 and 3 (7 units), for a total of 10 time units. |
//题意:有n头牛要去第x头牛的住处参加party。。参加完还要返回。。
先输入n,m,x;分别表示有n头牛,m条路单向,单向的,单向的路(重要的说三遍),x表示要去的终点。因为牛都比较懒,所以他们都会采取最短路的方式去和返回,现在问这n头牛中要花费最长时间的牛的时间。
//思路:
来回单向最短路,因为n的范围是(n<1000),所以用笛杰斯特拉就行了。平常我们写的都是去的,这块就要新学到点东西了,这里直接求得来回的最短路(很机智)。
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #define INF 0x3f3f3f3f #define ull unsigned long long #define ll long long #define IN__int64 #define N 1010 #define M 1000000007 using namespace std; int map ; int a ; int vis ,dis ;//回去的最短距离 int vis1 ,dis1 ;//去的时候的最短距离 int n,m; int djs(int y) { memset(vis,0,sizeof(vis)); memset(dis,INF,sizeof(dis)); memset(vis1,0,sizeof(vis1)); memset(dis1,INF,sizeof(dis1)); dis[y]=0;dis1[y]=0; int i,j,k,k1; for(j=1;j<=n;j++) { k=-1;k1=-1; for(i=1;i<=n;i++) { if(!vis[i]&&(k==-1||dis[i]<dis[k])) k=i; if(!vis1[i]&&(k1==-1||dis1[i]<dis1[k1])) k1=i; } vis[k]=1;vis1[k1]=1; for(i=1;i<=n;i++) { dis[i]=min(dis[i],dis[k]+map[k][i]);//回去 dis1[i]=min(dis1[i],dis1[k1]+map[i][k1]);//来 } } } int main() { int i,j,k,x; while(scanf("%d%d%d",&n,&m,&x)!=EOF) { int u,v,w; memset(map,INF,sizeof(map)); memset(a,0,sizeof(a)); for(i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&w); if(map[u][v]>w) map[u][v]=w; } djs(x); int mm=0; for(i=1;i<=n;i++) { if(i==x) continue; mm=max(mm,dis[i]+dis1[i]); } printf("%d\n",mm); } return 0; }
POJ - 3181 Dollar Dayz
Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1 each or 1 tool at $3 and an additional 1 tool at $2. Of course, there are other combinations for a total of 5 different ways FJ can spend all his money on tools. Here they are: 1 @ US$3 + 1 @ US$2 1 @ US$3 + 2 @ US$1 1 @ US$2 + 3 @ US$1 2 @ US$2 + 1 @ US$1 5 @ US$1 Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100). Input A single line with two space-separated integers: N and K. Output A single line with a single integer that is the number of unique ways FJ can spend his money. Sample Input 5 3 Sample Output 5 |
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<iostream> #define INF 1000000000000000000 #define ull unsigned long long #define ll long long #define IN __int64 #define N 1010 #define M 1000000007 using namespace std; ll a ,b ; int main() { int n,k; while(scanf("%d%d",&n,&k)!=EOF) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); b[0]=1; for(int i=1;i<=k;i++) { for(int j=i;j<=n;j++) { a[j]=a[j]+a[j-i]+(b[j]+b[j-i])/INF; b[j]=(b[j]+b[j-i])%INF; } } if(a ) printf("%lld",a ); printf("%lld\n",b ); } return 0; }
相关文章推荐
- HDU 1056
- win10企业版安装CAD Electrical2016提示缺少.net4.5该怎么办?
- 03-27-学习进度条
- Uboot启动分析之Start.S
- View setSystemUiVisible 测试
- 思考各种编程语言是如何适应运行环境(调用外设)的?
- 并发编程
- 62. Unique Paths
- 第五周实践项目1————三角形雏形(4)
- meanshift运动跟踪算法详解
- 随机数字的大小排列
- 课堂实验4.1(环数组)
- //6.5 定义一个日期类 Date,该类对象存放一个日期,可以提供的操作有: //void GetDate(); //取日期值,格式如“2001 年 2 月 5 日” //void GetYear(
- JavaScript
- nyist 740 “炫舞家“ST
- 论调用开放API接口获取ip相关信息
- android view层次与位置大小
- 基于tiny6410的madplay播放器的移植
- Linux内核分析-系统中断在内核中的实现
- JS中call和apply