摘要: 题意:给出一个数集S中所有元素,问是否存在d属于S使得d=a+b+c,且a,b,c均属于S?若有,则输出最大的d 否则输出no solution做法:暴力就可以过的。代码如下:#include #include #include #define zzusing namespace std;const int MAXN = 1000 + 5;int s[MAXN];int main(){#ifndef zz freopen("in.txt","r",stdin);#endif int n; while(scanf("%d", & 阅读全文
posted @ 2013-02-05 18:18 ChrisZZ 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 题意:给定n个数字字符串,求他们能组成的最大数字字符串。做法:用,cmp比较函数比较s+t与t+s即可。代码:#include #include #include #include #include #define zzusing namespace std;bool cmp(const string&s, const string&t){ return s+t>t+s;}int main(){#ifndef zz freopen("in.txt", "r", stdin);#endif int n; while(scanf(&qu 阅读全文
posted @ 2013-02-05 17:33 ChrisZZ 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 题意:给出一个只可能包含0,1,2的字符串,给定需要的0的个数a和需要的1的个数b,使用最少的替换次数得到目标串,输出交换次数。做法:简单模拟即可代码:#include #include #include #include using namespace std;int main() { int n,a,b; string s; while(cin>>n>>a>>b>>s) { if(a+b>n) {puts("-1");continue;} int c = n-a-b, i; int x=count(s.begin() 阅读全文
posted @ 2013-02-05 15:56 ChrisZZ 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 题意:给定n个数,他们之间可以互相传递一定的值,每次传递有k%的损失,现在需要进行若干次传递使得最终每个数都等于所有数的均值。做法:设置两个量maxn和minn,不断地更新maxn和minn,直到两者相等。中间借助mid = (maxn+minn)/2进行比较。代码:#include #include using namespace std;const int MAXN = 10000 + 5;const double eps = 1e-6;double a[MAXN];int main(){// freopen("in.txt", "r", stdin 阅读全文
posted @ 2013-02-05 15:54 ChrisZZ 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 题意:有一块草坪,长为l,宽为w,在其中心线的不同位置处装有n个点状的喷水装置,每个装置i可以将以它为中心,半径为ri的圆形区域润湿,清选择尽量少的喷水装置,把整个草坪全部润湿。分析:其实是一个最小区间覆盖的问题,用最少的区间覆盖给定的区间。代码:#include #include #include using namespace std;const int MAXN = 11111;double l, w;paira[MAXN];int main(){ int n; while(scanf("%d%lf%lf", &n, &l, &w)!=EOF) 阅读全文
posted @ 2013-02-05 15:50 ChrisZZ 阅读(282) 评论(0) 推荐(0) 编辑