标签:des style blog http io color ar os sp
本厂做了3个水体,被略哭
水题1 暴力乱搞
题目:
27228 37649
3 27228--->109500--->115401--->219912 2 37649--->132322--->355553
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<map> #include<vector> #include<cmath> #include<string> #include<queue> #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; const int maxn=1000000; int n,path[maxn]; char str[maxn],xx[maxn],yy[maxn]; bool isprime(int n) { itoa(n,str,10); int len=strlen(str); for(int i=0;i<len/2;i++) { if(str[i]!=str[len-i-1]) return false; } return true; } int main() { int ok,cnt,temp; while(~scanf("%d",&n)) { cnt=0; path[++cnt]=n; ok=1; while(ok) { if(!isprime(n)) { int zz=0; itoa(n,xx,10); int len=strlen(xx); for(int i=len-1;i>=0;i--) { yy[zz]=xx[i]; zz++; } yy[zz]='\0'; n=n+atoi(yy); path[++cnt]=n; } else ok=0; } printf("%d\n",cnt-1); for(int i=1;i<cnt;i++) printf("%d--->",path[i]); printf("%d\n",path[cnt]); } return 0; }
UVA10954 ADD ALL(优先队列)
可以说是哈弗曼模型吧
就是给n个数,然后求n个数的和的和最小
就是构造一个数越小优先级越高的队列,每次取前两位,然后求累加和即可
题目:
Problem F
Add All
Input: standard input
Output: standard output
Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, let’s add some flavor of ingenuity to it.
Addition operation requires cost now, and the cost is the summation of those two to be added. So, to add 1 and 10, you need a cost of11. If you want to add 1, 2 and 3. There are several ways –
1 + 2 = 3, cost = 3 3 + 3 = 6, cost = 6 Total = 9 |
1 + 3 = 4, cost = 4 2 + 4 = 6, cost = 6 Total = 10 |
2 + 3 = 5, cost = 5 1 + 5 = 6, cost = 6 Total = 11 |
I hope you have understood already your mission, to add a set of integers so that the cost is minimal.
Each test case will start with a positive number, N (2 ≤ N ≤ 5000) followed by N positive integers (all are less than 100000). Input is terminated by a case where the value of N is zero. This case should not be processed.
For each case print the minimum total cost of addition in a single line.
3 1 2 3 4 1 2 3 4 0 |
9 19
|
Problem setter: Md. Kamruzzaman, EPS
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<cmath> #include<string> #include<queue> #include<vector> #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; const int maxn=5000+10; priority_queue<int,vector<int>,greater<int> >Q; int a[maxn],n; int main() { int last,ans; while(~scanf("%d",&n),n) { while(!Q.empty()) Q.pop(); ans=0; for(int i=1;i<=n;i++) { scanf("%d",&last); Q.push(last); } for(int i=1;i<n;i++) { int a=Q.top();Q.pop(); int b=Q.top();Q.pop(); last=a+b; ans+=last; Q.push(last); } printf("%d\n",ans); } return 0; }
题目:
2 4 5 0 1 10 0 2 20 2 3 40 1 3 10 1 2 70 1 1 4 1 60 2 2 3 3 3 0 1 20 2 1 40 2 0 70 2 3 0 3 10 1 4 90 2 4 100 0
70 160
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<cmath> #include<string> #include<queue> #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; priority_queue<int,vector<int>,greater<int> >Q; const int maxn=1000+10; bool vis[maxn]; int cnt,yy,root[maxn]; struct Edge { int u,v,w; }edge[maxn*maxn]; bool cmp(Edge a,Edge b) { return a.w<b.w; } int findroot(int x) { if(root[x]!=x) root[x]=findroot(root[x]); return root[x]; } int kruscal(int n) { for(int i=0;i<maxn;i++) root[i]=i; int l,r,ans=0; int xx=0; for(int i=1;i<=cnt;i++) { int l=edge[i].u; int r=edge[i].v; int val=edge[i].w; if(vis[l]||vis[r]) continue; else { int fx=findroot(l); int fy=findroot(r); if(fx==fy) continue; else { root[fx]=fy; // printf("%d %d %d\n",l,r,val); ans+=val; xx++; if(xx==n-1) return ans; } } } return -1; } int main() { int t,n,m,sum,l,r,mid,newc,newr,old; scanf("%d",&t); while(t--) { memset(vis,false,sizeof(vis)); cnt=0; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d%d",&l,&r,&mid); edge[++cnt].u=l; edge[cnt].v=r; edge[cnt].w=mid; // printf("%d %d %d\n",l,r,mid); } scanf("%d%d",&newc,&newr); for(int i=1;i<=newr;i++) { scanf("%d%d%d",&l,&r,&mid); edge[++cnt].u=l; edge[cnt].v=r; edge[cnt].w=mid; // printf("%d %d %d\n",l,r,mid); } scanf("%d",&old); for(int i=1;i<=old;i++) { scanf("%d",&l); vis[l]=true; } sort(edge+1,edge+1+cnt,cmp); int ans=kruscal(n+newc-old); if(ans==-1) printf("what a pity!\n"); else printf("%d\n",ans); } return 0; }
我竟然看样例那个神奇的字母是B,然后就以为不变了
哎 直接枚举A--Z看哪个字母满足条件即可,
题目:
30 17 6 9 8 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13 18 19 16 17 22 23 20 21 26 27 24
SDKJABCDEFGHIJKLMNOPQRSTUVWXYZ
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<vector> #include<cmath> #include<string> #include<queue> #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; priority_queue<int,vector<int>,greater<int> >Q; const int maxn=10000+10; int a[maxn],n; int main() { char ch; int i,j; while(~scanf("%d",&n)) { for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=0;i<26;i++) { ch=i+'A'; for(j=1;j<=n;j++) { if((a[j]^ch)<'A'||(a[j]^ch)>'Z') break; } if(j==n+1) break; } //printf("%c\n",ch); for(int i=1;i<n;i++) printf("%c",ch^a[i]); printf("%c\n",ch^a[i]); } return 0; }
标签:des style blog http io color ar os sp
原文地址:http://blog.csdn.net/u014303647/article/details/41182821