周赛(一)
来源:互联网 发布:公司内部流程优化 编辑:程序博客网 时间:2024/04/29 18:53
A
HDU - 2106
Description
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
Output
Sample Input
31(2)2(3)3(4)411(10)11(2)11(3)11(4)
Sample Output
623
#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 1000000007using 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
Description
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
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
Sample Input
3 1 3 24 1 2 3 44 3 3 2 10
Sample Output
4103
#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 1000000007using namespace std;ll dp[N];ll a[N];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
Description
Input
Output
Sample Input
52 3 5 7 1252 16 64 256 10240
Sample Output
12no 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 1000000007using 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--;elsel++;}if(ans!=INF)break;}if(ans!=INF)break;}if(ans==INF)printf("no solution\n");elseprintf("%d\n",ans);}return 0;}
HDU - 1443
Description
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
Output
Sample Input
340
Sample Output
530
#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 1000000007using 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
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
20 11 0
2 1
50 2 2 1 22 0 4 1 32 4 0 1 31 1 1 0 12 3 3 1 0
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[n]);}return 0;}
Description
Input
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
Sample Input
333 3 310 5 131 3 16 2 371 4 6 4 2 4 33 2 1 7 6 5 4
Sample Output
035
#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 1000000007using namespace std;struct zz{int d;int f;}p[N];bool cmp(zz a,zz b){return a.f>b.f;}int a[N];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
Description
Input
Output
Sample Input
31 2 439 2 1
Sample Output
024 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 1000000007using namespace std;int a[N],b[N],c[N],d[N];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];elseb[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
Description
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
Output
Sample Input
420
Sample Output
0.666670.28377
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#define ll long long#define N 1010#define M 1000000007using 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[n]);}return 0;}
POJ - 3268
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
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
Sample Input
4 8 21 2 41 3 21 4 72 1 12 3 53 1 23 4 44 2 3
Sample Output
10
Hint
#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 1000000007using namespace std;int map[N][N];int a[N];int vis[N],dis[N];//回去的最短距离 int vis1[N],dis1[N];//去的时候的最短距离 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;}
Description
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$1Write 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
Output
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 1000000007using namespace std;ll a[N],b[N];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[n])printf("%lld",a[n]);printf("%lld\n",b[n]);}return 0;}
- 周赛(一)
- (一)
- (一)
- (一)
- (一)
- (一)
- hibernate一二级缓存(一)
- 每日一题(一)
- 一、对象导论(一)
- NYIST_12周赛(一)题目题解
- 万能的一玄:一玄创业故事(一)
- python(一)端口扫描器(一)
- C每日一读(一)
- 每日一植物(一) -- 虎皮兰
- 第六周 项目一(一)
- opencv打开一幅图像(一)
- 一.Java编程基础(一)
- 蚂蚁问题 每日一练(一)
- 视频播放
- 通过UIActivityViewController实现更多分享服务
- win10系统调用架构分析
- js实现复制到粘贴板 ZeroClipboard
- 【追求进步】栈的压入、弹出序列
- 周赛(一)
- JAVA IO流
- Android-使用TimerPicker和DatePicker选择时间和日期
- 虚拟机热迁移api流程(一)
- BestCoder Round #77
- 淘宝的SEM如何操作及“车神”的由来太原网络营销师揭秘
- 大数相加
- 删除所有相同的元素
- Sublime Text 中使用Markdown