UVALIVE 4887 Soccer UVELIVE 4882

2024-08-24 11:58
文章标签 uvalive 4887 soccer uvelive 4882

本文主要是介绍UVALIVE 4887 Soccer UVELIVE 4882,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2015 UESTC Winter Training #6 训练赛的两道搜索模拟题


uvalive 4882

//      whn6325689
//		Mr.Phoebe
//		http://blog.csdn.net/u013007900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <numeric>
#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define MID(x,y) (x+((y-x)>>1))
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LLINF 1LL<<62template<class T>
inline bool read(T &n)
{T x = 0, tmp = 1; char c = getchar();while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();if(c == EOF) return false;if(c == '-') c = getchar(), tmp = -1;while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();n = x*tmp;return true;
}
template <class T>
inline void write(T n)
{if(n < 0){putchar('-');n = -n;}int len = 0,data[20];while(n){data[len++] = n%10;n /= 10;}if(!len) data[len++] = 0;while(len--) putchar(data[len]+48);
}
//-----------------------------------const int MAXN=1010;char str[MAXN];//Íâ³ËÇÒÄÚ·Ç³Ë string dfs(string s, int &g)
{string res = "", s1 = "", s2;int len = s.length(), g2, t = 2, i = 0;g = 2;while(i < len){if(s[i] == '('){int f = 0;s2 = "";do{if(s[i] == '('){if(f++)s2 += s[i];}else if(s[i] == ')'){if(--f)s2 += s[i];}elses2 += s[i];i++;}while(i < len && f);s2 = dfs(s2, g2);//cout << s2 << endl;if(t == 2){s1 = s2;t = g2;}else{if(!g2)s2 = '(' + s2 + ')';if(t)s1 += s2;else{s1 = '(' + s1 + ')' + s2;t = 1;}}}else if(s[i] == '+'){res += s1 + '+';g = 0;s1 = "";t = 2;i++;}else{while(i < len && s[i] != '(' && s[i] != '+'){if(t == 2){s1 += s[i];t = 1;}else if(t)s1 += s[i];else{s1 = '(' + s1 + ')' + s[i];t = 1;}i++;}}}if(res == "")g = t;g = g > 0;return res + s1;
}int main()
{
//	freopen("data.txt","r",stdin);while(~scanf("%s",str)){int j;printf("%s\n",dfs(string(str),j).c_str());}return 0;
}

uvalive 4887

//      whn6325689
//		Mr.Phoebe
//		http://blog.csdn.net/u013007900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <numeric>
#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define MID(x,y) (x+((y-x)>>1))
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LLINF 1LL<<62template<class T>
inline bool read(T &n)
{T x = 0, tmp = 1; char c = getchar();while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();if(c == EOF) return false;if(c == '-') c = getchar(), tmp = -1;while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();n = x*tmp;return true;
}
template <class T>
inline void write(T n)
{if(n < 0){putchar('-');n = -n;}int len = 0,data[20];while(n){data[len++] = n%10;n /= 10;}if(!len) data[len++] = 0;while(len--) putchar(data[len]+48);
}
//-----------------------------------map<string,int > id;
vi l,r;
char s[222],ss[222];int n;
int base[22],rank[22],st[22],tob[22];
int mx[22],mi[22];
string name[22];bool cmp(int x,int y)
{return tob[x]>tob[y];
}void dfs(int dep)
{if(dep==l.size()){for(int i=0;i<=n;i++){rank[i]=i;tob[i]=base[i];}for(int i=0;i<l.size();i++){if(!st[i]){tob[l[i]]++;tob[r[i]]++;}else if(st[i]==1)tob[l[i]]+=3;elsetob[r[i]]+=3;}sort(rank+1,rank+n+1,cmp);int cur=1;for(int i=1;i<=n;i++){if(tob[rank[i]]!=tob[rank[i-1]])cur=i;mx[rank[i]]=max(mx[rank[i]],cur);mi[rank[i]]=min(mi[rank[i]],cur);}}else{st[dep]=0;dfs(dep+1);st[dep]=1;dfs(dep+1);st[dep]=2;dfs(dep+1);}
}void pu(int x)
{if (x == 1)printf("1st");else if (x == 2)printf("2nd");else if (x == 3)printf("3rd");elseprintf("%dth", x);
}int main()
{
//	freopen("data.txt","r",stdin);int m,a,b,x,y,len,cas=0;while(read(n)&&read(m)&&(n+m)){if(cas++)putchar('\n');id.clear();l.clear();r.clear();CLR(base,0);base[0]=-1;for(int i=1;i<=n;i++){cin>>name[i];id[name[i]]=i;}while(m--){scanf("%s vs %s %d %d",s,ss,&a,&b);len=strlen(ss);ss[len-1]='\0';
//			cout<<s<<" "<<ss<<endl;x=id[s];y=id[ss];if(~a){if(a==b){base[x]++;base[y]++;}else if(a>b)base[x]+=3;elsebase[y]+=3;}else{l.pb(x);r.pb(y);}}CLR(mi,INF);CLR(mx,-INF);dfs(0);for (int i=1;i<=n;i++){printf("Team %s can finish as high as ",name[i].c_str());pu(mi[i]);printf(" place and as low as ");pu(mx[i]);puts(" place.");}}return 0;
}


这篇关于UVALIVE 4887 Soccer UVELIVE 4882的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1102420

相关文章

【UVALive】6709 Mosaic 二维线段树

传送门:【UVALive】6709 Mosaic 题目大意: 每次选择矩阵中的一个点,求以他为中心,边长为D(D一定是奇数)的矩阵中的最小值min和最大值max,输出ans =(min+max)/ 2(向下取整)。然后将该点的值修改为ans。 题目分析: 赤果果的二维线段树单点修改、区间查询。 又一次学习了线段树,发现原来所有的更新操作全部放在二维中即可。 很不错,一定要经常看看,温

【UVALive】3887 Slim Span 枚举+最小生成树

传送门:【UVALive】3887 Slim Span 题目大意:给出一个n(2 <= n <= 100)个结点的无向图,找一棵苗条度(最大边减最小边的值)最小的生成树。图中不含自环或重边。 题目分析:枚举最小边求生成树即可。模板用用萌萌哒~ 代码如下: #include <cstdio>#include <cstring>#include <algorit

【UVALive】5713 Qin Shi Huang's National Road System 最小生成树

传送门:【UVALive】5713 Qin Shi Huang's National Road System 题目大意:秦朝有n个城市,需要修建一些道路使得任意两个城市之间都可以连通。道士徐福声称他可以用法术修路,不花钱,也不用劳动力,但只能修一条路,因此需要慎重选择用法术修哪一条路。秦始皇不仅希望其他道路的总长度B尽量短(这样可以节省劳动力),还希望法术连接的两个城市的人口之和A尽量大,因此下

【UVALive】3661 Animal Run 平面图最小割 最短路

传送门:【UVALive】3661 Animal Run 题目大意:给你一个n*m个点的网格图,其中动物园在左上角,动物们的目的地在右下角,现在你需要派出一些工作人员拦截某些边使得没有一只动物能到达右下角,已知每个单元网格中存在左上角到右下角的对角线,网格中的边以及对角线都是双向的,每条道路有个权值,表示拦截这条边所需要的工作人员数。你的任务是派尽量少的工作人员使得达到目的。 题目分析

【UVALive】2965 Jurassic Remains 中途相遇法

传送门:【UVALive】2965 Jurassic Remains 题目分析:本题用了一个很不错的思想——中途相遇法。 因为题目的数据很小,我们很容易想到暴力,但是2^24次方的枚举依旧复杂度太大,因此我们可以这么做:将一半的串枚举异或能得到的所有的值,插入到map中,然后再枚举异或另一半的串能得到的所有的值,然后查找map中的与这个值相同的有没有,更新一下能得到的最大数量即可。 成

【UVALive】6163 Myth Busters 类24点

传送门:【UVALive】6163 Myth Busters 题目分析: 可以使用括号,还有加减乘除,问能否用四个0~9的数凑出10。。。我了个去。。渣渣不会写拿来当模拟写了,写的人都要吐了。。。。 先处理出所有两个数和起来的情况,然后用两个数和起来的情况再加上一个数处理出所有三个数和起来的情况,最后用两个两个数或者一个三个数加一个数的继续推出四个数的,最后按照不降序保存。 这个能一

UVALive 4255 Guess

题意: 给你半个矩阵  如果(i,j)的位置是'-'  则说明sum[i...j]<0  如果是'+'  说明sum>0  如果是'0'  说明sum=0  给出一种满足这个矩阵的序列  序列元素绝对值在10以内 思路: 很容易想到的是将sum[i...j]转化为sum[j]-sum[i-1]  即用前缀和来表示  那么题中的矩阵就可以转化成前缀和之间的大小比较  也就是说  我们可以通过

UVALIVE 5000 Underwater Snipers(二分+贪心)

二分答案 贪心判断 // whn6325689// Mr.Phoebe// http://blog.csdn.net/u013007900#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <climits>#include <comple

HDU 5150 UVALive 5061 (LCA标记)

这两题都是在树上求某一些路径上的点权的变化 两道题的思路相同 HDU 5150: 每一种颜色我们分开考虑他们对所有节点的贡献,对于颜色同为c的两个节点u和v(假设u!=v),那么在lca(u,v)的时候我们需要-1,因为在lca(u,v)一直到根的路径上,颜色c只能影响一次。基于此,我们对每种颜色的所有节点按照dfs序排好序,首先每个节点+1,然后对dfs序相邻的两个节点(注意颜色要相同)求

UVAlive 6426 Count【读入】

You have: • A matrix of natural numbers, with the property that all rows and all columns are sorted in ascending order (i.e. A[i,j]≥A[i−1,j] A[i,j] ≥ A[i−1,j] and A[i,j]≥A[i,j−1] A[i,j] ≥ A[i,j −1]