标签:uil case sts center otto efi mis rmi 1.2
本厂做了3个水体,被略哭
水题1 暴力乱搞
题目:
比如:68变成154(68+86)。再变成605(154+451),最后变成1111(605+506),而1111是回文数。于是有数学家提出一个猜想:不论開始是什么正整数,在经过有限次正序数和倒序数相加的步骤后,都会得到一个回文数。至今为止还不知道这个猜想是对还是错。如今请你编程序验证之。
特别说明:输入的数据保证中间结果小于2^31。
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; }
codeforces 475 B. Strongly Connected City
这个题目是求全图的联通,由于数据范围非常小。所以直接枚举全部的顶点,然后保搜得到全部的点。
最后看是否所有联通。我sb的把数组开小。导致调了一个中午,哎。郁闷啊
题目链接:
题目:
Imagine a city with n horizontal streets crossing m vertical streets, forming an (n?-?1)?×?(m?-?1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.
The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
The first line of input contains two integers n and m, (2?≤?n,?m?≤?20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length n, made of characters ‘<‘ and ‘>‘, denoting direction of each horizontal street. If the i-th character is equal to ‘<‘, the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.
The third line contains a string of length m, made of characters ‘^‘ and ‘v‘, denoting direction of each vertical street. If the i-th character is equal to ‘^‘, the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
If the given pattern meets the mayor‘s criteria, print a single line containing "YES", otherwise print a single line containing "NO".
3 3 ><> v^v
NO
4 6 <><> v^v^v^
YES
#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=20+10; struct Node { int a,b; }node[maxn*maxn]; bool vis[maxn*maxn][maxn*maxn]; char path[maxn]; int n,m; void dfs(int xx,int yy) { if(vis[xx][yy]) return; else { vis[xx][yy]=true; if(node[yy].a==0&&yy%m!=1) dfs(xx,yy-1); else if(node[yy].a==1&&yy%m!=0) dfs(xx,yy+1); if(node[yy].b==0&&yy>m) dfs(xx,yy-m); else if(node[yy].b==1&&yy<(n*m-m+1)) dfs(xx,yy+m); } } int main() { int ok; while(~scanf("%d%d",&n,&m)) { ok=1; scanf("%s",path+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(path[i]==‘<‘) node[m*(i-1)+j].a=0; else node[m*(i-1)+j].a=1; } scanf("%s",path+1); for(int j=1;j<=m;j++) for(int i=1;i<=n;i++) { if(path[j]==‘^‘) node[m*(i-1)+j].b=0; else node[m*(i-1)+j].b=1; } for(int i=1;i<=n*m;i++) { memset(vis,false,sizeof(vis)); dfs(i,i); for(int j=1;j<=n*m;j++) { if(!vis[i][j]) { ok=0; break; } } if(!ok) break; } if(!ok) puts("NO"); else puts("YES"); } return 0; }
标签:uil case sts center otto efi mis rmi 1.2
原文地址:http://www.cnblogs.com/ljbguanli/p/6978349.html