1、CodeForces 337A Puzzles

题意:
①在有m个整数的集合中
②找到有n个整数的子集
③再比较这些子集中元素的最大值与最小值的差值
④输出最小的差值
解题思路:
①将集合中的元素从大到小排序,就可以把集合看成一个有序的序列
②比较长度为n的子序列的 “头” 和 “尾” 的差

我:
训练开始不久很多人都AC了
面对这种题我的思绪已经混乱了…
看了别人代码才懂的
用sort做的时候写比较函数写错了,写成下面这样

int cmp_num(int x, int y)
{return (x - y);
}

WA一次
练得太少,尤其是思维锻炼

#include <iostream>
#include <cstdio>
#include <algorithm>using namespace std;const int maxn = 50 + 5;
int f[maxn];int cmp_num(int x, int y)
{return (x > y);
}int main()
{
//    freopen("in.txt", "r", stdin);int n, m;while (cin>>n>>m) {for (int i=0; i<m; ++i) {cin>>f[i];}sort(f, f+m, cmp_num);int Min = INT_MAX;for (int i=0, j=n-1; j<m; ++i,++j) {int t = f[i] - f[j];if (t < Min) {Min = t;}}cout<<Min<<endl;}return 0;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>using namespace std;const int maxn = 50 + 5;
int f[maxn];int cmp_num(const void *a, const void *b)
{return *(int *)b - *(int *)a;
}int main()
{
//    freopen("in.txt", "r", stdin);int n, m;while (cin>>n>>m) {for (int i=0; i<m; ++i) {cin>>f[i];}qsort(f, m, sizeof(f[0]), cmp_num);int Min = INT_MAX;for (int i=0, j=n-1; j<m; ++i,++j) {int t = f[i] - f[j];if (t < Min) {Min = t;}}cout<<Min<<endl;}return 0;
}

2、CodeForces 520A Pangram

题意:
给一个长度为n的字符串,判断26个英文字母(不论大小写)是否都出现过

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>using namespace std;char s[150];
int vis[30];int main()
{
//    freopen("in.txt", "r", stdin);int n;while (cin>>n) {memset(vis, 0, sizeof(vis));int Count = 0;for (int i=0; i<n; ++i) {cin>>s[i];if (s[i]>='A' && s[i]<='Z') {s[i] += ('a' - 'A');}if (!vis[s[i]-'a']) {vis[s[i]-'a'] = 1;++Count;}}if (Count == 26) {cout<<"YES"<<endl;} else {cout<<"NO"<<endl;}}return 0;
}

3、CodeForces 635A Orchestra

题意:
①给一个r行c列的图
②对图中的n个点进行标记
③找出至少包含k个被标记点的子矩形

解题思路:暴力
①遍历图中所有的点
②找到以该点为左上角的所有矩形
③再遍历这些矩形中的所有点进行判断

我:
CF的A题,搞了几个小时…..
注意有可能输入的k可能和下面定义的k混淆

#include <iostream>
#include <cstring>
#include <cstdio>using namespace std;const int maxn = 10 + 5;
int Graph[maxn][maxn];int main()
{
//    freopen("in.txt", "r", stdin);int r, c, n, K;while (cin>>r>>c>>n>>K) {memset(Graph, 0, sizeof(Graph));int x, y;for (int i=0; i<n; ++i) {cin>>x>>y;Graph[x][y] = 1;}int num = 0;int i, j, k, l, a, b;for (i=1; i<=r; ++i) {for (j=1; j<=c; ++j) {for (k=i; k<=r; ++k) {for (l=j; l<=c; ++l) {int Count = 0;for (a=i; a<=k; ++a) {for (b=j; b<=l; ++b) {if (Graph[a][b] == 1) {++Count;}}}if (Count >= K) {
//                            cout<<i<<" "<<j<<" - "<<k<<" "<<l<<endl;++num;}}}}}cout<<num<<endl;}return 0;
}

4、HDU 1597 find the nth digit

感觉挂这道题是用来练习二分的,但是我们大多人都是用了比较简单的数学方法

#include <iostream>
#include <cstdio>using namespace std;int main()
{
//    freopen("in.txt", "r", stdin);int K;while (cin>>K) {while (K--) {int N;cin>>N;int x = 1;while (N > x) {N -= x;++x;}if (N % 9 == 0) {cout<<9<<endl;} else {cout<<N%9<<endl;}}}return 0;
}

5、hihoCoder 1245 王胖浩与三角形

题意:
①有一个三角形,三边长为a,b,c
②可以增加三条边的边长,增加的总长度不能超过l
③求三角形最大的面积

解题思路:
让三个边的差值尽可能的小

我:
第一次AC:
提交时间:2015-12-22 17:17:25
第二次AC:
提交时间:2016-03-29 15:27:38

#include <iostream>
#include <iomanip>
#include <math.h>using namespace std;double S(double a,double b,double c)
{double p;double s;p = (a + b + c) / 2.0;s = sqrt(p * (p-a) * (p-b) * (p-c));return s;
}int main()
{int T;double a,b,c,l,s,M,L;double area;int i;cout.setf(ios::fixed);while (cin>>T) {while (T--) {cin>>a>>b>>c>>l;s = L = a;if (b > L) {L = b;}if (b < s) {s = b;}if (c > L) {L = c;}if (c < s) {s = c;}M = a + b + c - s - L;if (l-(M-s) > 0) {l -= (M-s);s = M;} else {s += l;l = 0;}if (l>0.0 && l>(2.0*(L-M))) {l -= (2.0*(L-M));s = M = L;} else {s += (l/2.0);M += (l/2.0);l = 0;}if (l>0.0) {s += (l/3.0);M += (l/3.0);L += (l/3.0);}//            cout<<s<<" "<<M<<" "<<L<<endl;area = S(s,M,L);cout<<setprecision(10)<<area<<endl;}}return 0;
}
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>using namespace std;#define Max(a, b) ((a > b) ? a : b)
#define Min(a, b) ((a < b) ? a : b)double S(double a, double b ,double c);
//double area(double x1, double y1, double x2, double y2, double x3, double y3);int main()
{
//    freopen("in.txt", "r", stdin);int T;cout.setf(ios::fixed);while (cin>>T) {while (T--) {double a, b, c, l;cin>>a>>b>>c>>l;double high, mid, low;high = Max(Max(a, b), Max(b, c));low = Min(Min(a, b), Min(b, c));mid = (a+b+c) - (high+low);double t = mid - low;if (l > t) {l -= t;low = mid;} else {low += l;l = 0;}t = 2.0 * (high - mid);if (l > t) {l -= t;low = mid = high;} else {low += l/2.0;mid += l/2.0;l = 0;}if (l > 0) {low += (l/3.0);mid += (l/3.0);high += (l/3.0);}cout<<setprecision(10)<<S(low, mid, high)<<endl;}}return 0;
}double S(double a, double b, double c)
{double t;double s;t = (a + b + c) / 2.0;s = sqrt(t * (t-a) * (t-b) * (t-c));return s;
}[6、团体程序设计天梯赛-练习集 L2-008 最长对称子串](https://www.patest.cn/contests/gplt/L2-008)
------------------------------------------------------------------------
暴力搜

include

include

include

include

using namespace std;

typedef long long ll;

const int maxn = 1000 + 10;
char s[maxn];

int main()
{
gets(s);
int Max = 1;
int len = strlen(s);
for (int i = 0; i < len; ++i) {
int t;
if (i+1 < len && s[i] == s[i+1]) {
t = 2;
for (int j = i-1, k = i+2; j>=0 && k < len && s[j] == s[k]; –j, ++k) {
t += 2;
}
if (t > Max) {
Max = t;
}
}
if (i+2 < len && s[i] == s[i+2]) {
t = 3;
for (int j = i-1, k = i+3; j>=0 && k < len && s[j] == s[k]; –j, ++k) {
t += 2;
}
if (t > Max) {
Max = t;
}
}
}
printf(“%d\n”, Max);
return 0;
}


[7、团体程序设计天梯赛-练习集 L1-006 连续因子](https://www.patest.cn/contests/gplt/L1-006)
------------------------------------------------------------------------
暴力搜
时间复杂度O(sqrt(n))

include

include

include

include

include

include

include

include

include

include

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const double eps = 1e-8;
const int INF = 0x7fffffff;
const int maxn = 1000;
int vis[maxn];
int num[maxn];

int main()
{
int N;
scanf(“%d”, &N);
int t = sqrt(N) + 1;
bool flag = true;
int Max = 0;
int key;
int Max_t;
for (int i = 2; i < t; ++i) {
Max_t = 0;
if (N%i == 0) {
flag = false;
int mul = i;
int add = 1;
while (N%mul == 0) {
++Max_t;
mul *= (i+add);
++add;
}
if (Max_t > Max) {
Max = Max_t;
key = i;
}
}
}
if (flag) {
printf(“1\n”);
printf(“%d\n”, N);
} else {
printf(“%d\n”, Max);
printf(“%d”, key);
for (int i = 0; i < Max - 1; ++i) {
printf(“*%d”, ++key);
}
printf(“\n”);
}
return 0;
}


[8、团体程序设计天梯赛-练习集 L1-009 N个数求和](https://www.patest.cn/contests/gplt/L1-009)
------------------------------------------------------------------------
注意输出细节

include

include

include

include

include

include

include

include

include

include

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 100 + 10;
ll a[maxn], b[maxn];

ll gcd(ll a, ll b);

int main()
{
int N;
scanf(“%d”, &N);
for (int i = 0; i < N; ++i) {
scanf(“%lld/%lld”, &a[i], &b[i]);
}
ll d = abs(gcd(a[0], b[0]));
ll ans_a = a[0] / d;
ll ans_b = b[0] / d;
for (int i = 1; i < N; ++i) {
ll lcm = ans_b / gcd(ans_b, b[i]) * b[i];
ans_a = ans_a * (lcm / ans_b) + a[i] * (lcm / b[i]);
ans_b = lcm;
d = abs(gcd(ans_a, ans_b));
ans_a /= d;
ans_b /= d;
}
ll t1 = ans_a / ans_b;
ll t2 = ans_a % ans_b;
if (t1 != 0 && t2 != 0) {
printf(“%lld %lld/%lld\n”, t1, t2, ans_b);
} else if (t2 != 0) {
printf(“%lld/%lld\n”, t2, ans_b);
} else if (t1 != 0) {
printf(“%lld\n”, t1);
} else {
printf(“0\n”);
}
return 0;
}

ll gcd(ll a, ll b)
{
return (a%b == 0) ? b : gcd(b, a%b);
}


[9、CodeForces_680A Bear and Five Cards](http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=399076)
------------------------------------------------------------------------
题意:
输入 5 个数,求减去 2 个或 3 个相同的数后的最小值

include

include

include

include

include

include

include

include

include

include

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
int t[10];
int vis[110];
bool vis_t[110];

int main()
{
memset(vis, 0, sizeof(vis));
memset(vis, false, sizeof(vis_t));
int sum = 0;
for (int i = 1; i <= 5; ++i) {
scanf(“%d”, &t[i]);
++vis[t[i]];
sum += t[i];
}
int Min = sum;
for (int i = 1; i < 5; ++i) {
if (vis[t[i]] >= 3 && !vis_t[t[i]]) {
if (Min > sum - t[i] * 3) {
Min = sum - t[i] * 3;
}
vis_t[t[i]] = true;
} else if (vis[t[i]] >= 2 && !vis_t[t[i]]) {
if (Min > sum - t[i] * 2) {
Min = sum - t[i] * 2;
}
vis_t[t[i]] = true;
}
}
printf(“%d\n”, Min);
return 0;
}


[10、CodeForces_680B Bear and Finding Criminals](http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=399032)
------------------------------------------------------------------------
题意:
给出 n 个城市中每个城市罪犯的数量(最多为 1)和警察的位置
若警察知道与他隔某个距离的位置有多少个罪犯(这个位置可能为2)
求他能锁定多少个罪犯解题思路:
首先他的位置若有罪犯,他就可以锁定一个
然后左右两边距离为 n 的位置都有城市,那么只有两个城市都有罪犯时才能锁定两个罪犯
若只有左边或右边有城市,那么只要这个城市有罪犯就可以锁定

include

include

include

include

include

include

include

include

include

include

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int maxn = 100 + 10;
int t[maxn];

int main()
{
int n, a;
scanf(“%d%d”, &n, &a);
for (int i = 1; i <= n; ++i) {
scanf(“%d”, &t[i]);
}
int Count = 0;
if (t[a] == 1) {
++Count;
}
int Left = a-1, Right = a+1;
while (Left >= 1 || Right <= n) {
if (Left >= 1 && Right <= n) {
if (t[Left] == 1 && t[Right] == 1) {
Count += 2;
}
–Left;
++Right;
} else if (Left >= 1) {
if (t[Left] == 1) {
++Count;
}
–Left;
} else if (Right <= n) {
if (t[Right] == 1) {
++Count;
}
++Right;
}
}
printf(“%d\n”, Count);
return 0;
}
“`

签到 2016.6.9相关推荐

  1. 签到 2016.6.17

    1.Google Code Jam Qualification Round 2016_B Problem The Infinite House of Pancakes has just introdu ...

  2. python3+任务计划实现的人人影视网站自动签到

    """ python3+任务计划实现的人人影视网站自动签到 2016年6月8日 09:52:28 codegay这是一个自动化程度较高的程序,运行本程序后会从chrome ...

  3. python自动关闭弹窗字幕_[原创]python3+任务计划实现的人人字幕网站自动签到

    """ python3+任务计划实现的人人字幕网站自动签到 2016年6月8日 09:52:28 codegay 这是一个自动化程度较高的程序,运行本程序后会从chrom ...

  4. 2016年CCPC/ICPC比赛总结

    2016:我大一升入大二. 队友:GLY,WZK. 队名:开心就好(MyHappinessIsAll) 菜鸡战绩:5月省赛二等,9月东北四省赛二等,9月CCPC长春打铁,10月ICPC沈阳压线铜牌. ...

  5. 2016极客大奖颁奖盛典落幕 50个大奖勾勒中国创新图谱

    1月13日,北京的天空迎来久违的"北京蓝",2016极客大奖年度评选(FromGeek Awards 2016)颁奖盛典也在京圆满落幕.颁奖活动现场,来自IT网络通信.新电商&am ...

  6. 2016 Multi-University Training Contest 3

    A - Sqrt Bo 签到题啦,直接套一个大数模板搞定. 不过我现在使用的大数模板不支持直接定义并赋值,bignum a = 1 这样是不行的. //查看了下代码发现,模板中bignum的构造函数, ...

  7. 【年度总结】2016年年度总结

    早晨醒来,在被窝里面刷着简书,看到一篇文章叫<深漂一年,一个资深程序员的2016年终告白>,写的很好,很有感触.在2016年的农历的最后一天,总是有很多感触要写下来.所以下午扫墓之后,我也 ...

  8. 【直播预告】创享未来 2016微软开发者峰会

    感谢所有中国开发者对2016微软开发者峰会的热情关注,目前活动已经截止报名了,不过M姐为大家带来新的福利: 2016微软开发者峰会将全程线上直播! 2016微软开发者峰会将全程线上直播! 2016微软 ...

  9. LSGO软件技术团队2015~2016学年第十七周(1221~1227)总结

    团队简述: LSGO软件技术团队成立于2010年10月,主要从事的应用方向为互联网与移动互联网(UI设计,前端开发,后台开发),地理信息系统:研究方向为大数据处理与机器学习.成立几年来为学校培养了一批 ...

最新文章

  1. BizTalk学习笔记系列之二:实例说明如何使用BizTalk
  2. C++容器适配器之priority_queue
  3. 无线轮播android,Android无限轮播Banner的实现
  4. 7-20上午上机题实现
  5. 【多线程高并发】jcstress并发测试工具使用教程详解
  6. springcloud(六):配置中心git示例
  7. view.post不执行的坑点
  8. 1218数据库操作工具类的使用
  9. asp.net中实现群发邮件功能
  10. 基于JAVA+Servlet+JSP+MYSQL的校园一卡通管理系统
  11. 我的世界基岩版json_我的世界基岩版下载_我的世界基岩版app下载_我的世界基岩版官网最新版下载-新手游网...
  12. 个人永久性免费-Excel催化剂插件功能修复与更新汇总篇之七
  13. 关于尚硅谷视频p135配置完yarn-site.xml的硬件资源配置后
  14. windows 如何查看文件夹所使用的图标
  15. 文字转语音文件现成工具
  16. cad卸载不干净_Mac软件卸载不干净?你可以试试AppCleaner
  17. ACM入门-最小生成树及其应用
  18. Hive的Rank函数
  19. 简单socket聊天小程序+socket简单封装
  20. LeetCode每日一题495. 提莫攻击

热门文章

  1. SYS.AUD$无法扩容导致无法登录的问题
  2. 12种外汇中常见的币种和货币对
  3. java 费用_java培训一般需要多少费用
  4. “不挣钱”的小鹏G3中期改款,又一场硬战「数观车市」
  5. 年终盘点: 2022 不容错过的 20 个开发者工具
  6. 拯救者14(i7-4720HQ)解决触控板设置项无法打开的问题过程记录
  7. MATLAB程序发布 MCC编译
  8. 14个支持响应式设计的前端框架
  9. 达梦HS搭建(DM-DM)_yxy
  10. winrar分卷压缩_WinRAR该让位了?免费开源的压缩软件横空出世