340 - Master-Mind Hints

/*读了老半天才把题读懂,读懂了题输出格式没注意,结果re了两次。

题意:先给一串数字S,然后每次给出对应相同数目的的一串数字Si,然后优先统计Si和S对应位相同并且相等的个数L,在统计不在对应位上但相等的的个数R.

当Si全0时,表示结束。

每个数只能用一次。

例如:有

S  1 3 5 5
S1 1 1 2 3
S2 4 3 3 5
Si . . . .
0 0 0 0 对于S1:则第一步只有第一个对应相等,所以L = 1
就还剩下3 5 5
    1 2 3,在统计R,下面只有3和上面的3相同,所以R = 1;
对于S2:L = 2,第二个位置和第四个位置对应相等。
就还剩下1 5
4 3,所以R = 0;依次类推。
*/
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#define N 1005
using namespace std; int n;
int a[N], b[N], c[N];
int main()
{
int i, j, t = , l, r;
while (cin>>n, n)
{
cout<<"Game "<<t++<<':'<<endl;
for (i = ; i < n; i++)
cin>>a[i];
while (true)
{
for (i = ; i < n; i++)
c[i] = a[i];
l = r = ;
for (i = ; i < n; i++)
{
cin>>b[i];
if (b[i] == c[i])/**< 统计对应位相等l的个数 */
{
l++;
c[i] = ;/**< 置相等位0,统计r时不影响 */
b[i] = -;
}
}
if (!b[])
break;
for (i = ; i < n; i++)
{
if (b[i] == -)
continue;
for (j = ; j < n; j++)
{
if (b[i] == c[j])/**< 统计r的个数 */
{
r++;
c[j] = ;
break;
}
}
}
cout<<" "<<'('<<l<<','<<r<<')'<<endl;
}
}
return ;
}

10420 - List of Conquests

 /*题意:统计每个国家有多少个人被Giovanni喜欢。

 并按字典序输出。
*/ #include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <climits>
#define N 2005
using namespace std;
struct node
{
string c;
int sum;
node()
{
c.clear();
sum = ;
}
bool operator >= (const node &b)
{
return c >= b.c;
}
friend istream& operator >> (istream &in, node &res)
{
in>>res.c;
return in;
}
friend ostream &operator << (ostream &out, const node &res)
{
out<<res.c<<' '<<res.sum<<endl;
return out;
}
bool operator == (const node &b)
{
return c == b.c;
} bool operator != (const node &b)
{
return c != b.c;
}
}; struct li
{
node s[N];
int p;
li()
{
p = ;
}
friend ostream &operator << (ostream &out, const li &res)
{
for (int i = ; i < res.p; i++)
out<<res.s[i];
}
void insert(const node &res)
{
if (p)
{
int l = , r = p - , mid;
while (l <= r)/**< 二分查找第一个比res大或等于的位置 */
{
mid = (l + r) >> ;
if (s[mid] >= res)/**< 如果大于等于,在左区间位置 */
r = mid - ;
else/**< 在右区间 */
l = mid + ;
}
if (s[l] != res)/**< 不存在,插入 */
{
for (r = p++; r > l; r--)
s[r] = s[r - ];
s[l] = res;
}
s[l].sum++;
return;
}
s[p] = res;
s[p++].sum++;
}
};
li a;
int main()
{
int n, i;
cin>>n;
string tt;
node t;
for (i = ; i < n; i++)
{
cin>>t;
getline(cin, tt);
a.insert(t);
}
cout<<a;
return ;
}

10474 - Where is the Marble?

/**< 题意:给一组数据无序,查询给定数在这组数出现的第一个位置(在有序中) */
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <climits>
#define N 10005
using namespace std;
int n, q; int sum[N], con[N];
int main()
{
int t = , i, m;
while (cin>>n>>q, n || q)
{
memset(con, , sizeof(con));
cout<<"CASE# "<<t++<<':'<<endl;
for (i = ; i < n; i++)
{
cin>>m;
con[m]++;/**< 计数排序,每个数不超过10000 */
}
sum[] = ;
sum[] = con[];
for (i = ; i < N; i++)
sum[i] = sum[i - ] + con[i - ];
for (i = ; i < q; i++)
{
cin>>m;
if (con[m])
cout<<m<<" found at "<<sum[m] + <<endl;
else
cout<<m<<" not found"<<endl;
}
}
return ;
}

152 - Tree's a Crowd

/**< 题意:(又是读了半天也没读懂,好纠结的英语)
在三维空间给一些点,计算每个点与其他点的距离,但只取最短距离,并统计最短距离在[0-10)的个数
比如某个点的最短距离在[1,2)之间,则对1这个位置的个数加1 */
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <climits>
#include <cmath>
#include <algorithm>
#include<iomanip>
#define N 5005 using namespace std;
struct node
{
int x, y, z;
/*
bool operator > (const node &b)
{
if (x == b.x)
{
if (y == b.y)
return z > b.z;
return y > b.y;
}
return x > b.x;
}*/
}a[N];
int con[];
int dis(const node &a, const node &b)
{
int x = a.x - b.x, y = a.y - b.y, z = a.z - b.z;
return int(sqrt(x * x + y * y + z * z));
} int cmp(const void *a, const void *b)/**< */
{
return ((node *)a)->x > ((node *)b)->x ? : -;
}
int main()
{
int n = , i, j, tm, t;
while (cin>>a[n].x>>a[n].y>>a[n].z, (a[n].x || a[n].y || a[n].z))
{
n++;
}
//qsort(a, n, sizeof(a[0]), cmp);
memset(con, , sizeof(con));
for (i = ; i < n; i++)
{
tm = ;
for (j = ; j < n; j++)
{
if (i != j)
{
t = dis(a[i], a[j]);
if (t < tm)
tm = t;
}
}
con[tm]++;
}
for (i = ; i < ; i++)
cout<<setw()<<con[i];
cout<<endl;
return ;
}

299 - Train Swapping

/**<
题目啰嗦了半天,就是火车进行从小到大重排序(冒泡排序)交换的次数
*/
#include <iostream>
#include <algorithm> using namespace std;
#define N 55
int a[N];
int main()
{
int n, l, i, j, s;
cin>>n;
while (n--)
{
cin>>l;
for (i = ; i < l; i++)
cin>>a[i];
s = ;
for (i = ; i < l; i++)
for (j = l - ; j > i; j--)
{
if (a[j] < a[j - ])
{
swap(a[j], a[j - ]);
s++;
}
}
cout<<"Optimal train swapping takes "<<s<<" swaps."<<endl;
}
return ;
}

120 - Stacks of Flapjacks

/**<  翻转从小到大排序*/
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define N 35 int a[N];
int main()
{
int i, j, n = , p, mm, t;
char ch = ;
while (ch != EOF && cin>>a[n])
{
ch = cin.get();
if (ch == ' ')
{
n++;
continue;
}
t = ++n;
cout<<a[];
for (i = ; i < n; i++)
cout<<' '<<a[i];
cout<<endl;
for (i = ; i < n; n--)
{
mm = a[i];
p = ;
for (j = ; j < n; j++)
{
if (mm < a[j])
{
mm = a[j];
p = j;
}
}
if (p != n - )
{
if (p)
{
reverse(a, a + p + );
reverse(a, a + n);
cout<<t - p<<' '<<t - n + <<' ';
}
else
{
reverse(a, a + n);
cout<<t - n + <<' ';
}
}
}
cout<<<<endl;
}
return ;
}

156 - Ananagrams

/**<
给一些单词,去掉相同字母且个数一样不区分大小写,再给剩下的单词进行排序输出
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define N 1005
using namespace std;
struct node
{
string str;
bool flag;
int tag[];
bool operator == (const node &b)
{
for (int i = ; i < ; i++)
if (tag[i] != b.tag[i])
return false;
return true;
}
bool operator > (const node &b)
{
return str > b.str;
}
node(const string &s)
{
str = s;
flag = false;
memset(tag, , sizeof(tag));
for (int i = ; s[i]; i++)
tag[(s[i] | ) - 'a']++;
}
node()
{
flag = false;
memset(tag, , sizeof(tag));
}
}s[N];
int p = ; void insert(const string &v)
{
if (!p)
{
s[p++] = v;
return;
}
for (int i = ; i < p; i++)
if (s[i] == v)
{
s[i].flag = true;
return;
}
int l = , r = p - , mid;
while (l <= r)
{
mid = (l + r) >> ;
if (s[mid] > v)
r = mid - ;
else
l = mid + ;
}
for (r = p++; r > l; r--)
s[r] = s[r - ];
s[l] = v;
} string t;
int main()
{
int i;
char ch;
cin.get(ch);
while (ch != '#')
{
t.clear();
while (ch == ' ' || ch == '\n')
cin.get(ch);
if (ch == '#')
break;
while (true)
{
t += ch;
cin.get(ch);
if (ch == ' ' || ch == '\n')
break;
}
insert(t);
}
for (i = ; i < p; i++)
if (!s[i].flag)
cout<<s[i].str<<endl;
return ;
}

400 - Unix ls

/**<
对输入的字符串进行排序,按格式输出,最后一列的宽度为所有字符串最长宽度,其余列的宽度为最长宽度加2.
要求输出所用的行最少
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iomanip> using namespace std;
#define N 105
string s[N];
int main()
{
int n, i, mm, len, j, t, k, kk;
while (cin>>n)
{
mm = ;
for (i = ; i < n; i++)
{
cin>>s[i];
len = s[i].length();
if (mm < len)
mm = len;
}
sort(s, s + n);
len = ( - mm) / (mm + ) + ;
for (i = ; i < ; i++)
cout<<'-';
cout<<endl;
cout<<left;
t = n / len;/**< 要输出t行len列 */
if (n % len)
t++;
for (i = ; i < t; i++)
{
kk = mm + ;
for (j = i, k = ; j < n; j += t, k++)
{
if (k == len)/**< 最后一列输出宽度为mm */
kk = mm;
cout<<setw(kk)<<s[j];
}
cout<<endl;
}
}
return ;
}

123 - Searching Quickly

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <set> using namespace std; struct snode
{
string str;
int x, y;/**< 字符串位置 */
bool operator < (const snode &b)const
{
if (str == b.str)
{
if (x == b.x)
return y < b.y;
return x < b.x;
}
return str < b.str;
}
snode()
{
str.clear();
x = y = ;
}
snode(string v, int xx, int yy)
{
str = v;
x = xx;
y = yy;
}
friend ostream & operator << (ostream &out, const snode &v)
{
out<<v.str<<' '<<v.x<<' '<<v.y;
return out;
}
}; set<string> ks;
multiset<snode> res;
string ts[]; int main()
{
int i, j, p;
string tmp;
ks.clear();
res.clear();
while (cin>>tmp, tmp != "::")
{
ks.insert(tmp);
}
i = ;
cin.get();
while (getline(cin, ts[i]))
{
j = ;
while (true)
{
p = j;
tmp.clear();
while (ts[i][j] && ts[i][j] != ' ')
{
ts[i][j] |= ;
tmp += ts[i][j++];
}
if (ks.find(tmp) == ks.end())/**< 不存在 */
res.insert(snode(tmp, i, p));
if (!ts[i][j])
break;
j++;
}
i++;
}
for (multiset<snode>::iterator it = res.begin(); it != res.end(); it++)
{
for (i = ; i < it->y; i++)
cout<<ts[it->x][i];
for (; ts[it->x][i] != ' ' && ts[it->x][i]; i++)/**< 大写 */
cout<<char(ts[it->x][i] & );
for (; ts[it->x][i]; i++)
cout<<ts[it->x][i];
//cout<<*it;
cout<<endl;
}
return ;
}

10194 - Football (aka Soccer)

#include <iostream>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map> using namespace std; struct snode
{
snode()
{
score = in = out = win = con = tie = lose = ;
name.clear();
_name.clear();
}
snode(string v)
{
score = in = out = win = con = tie = lose = ;
name = v;
_name.clear();
for (int i = ; v[i]; i++)
{
if (isalnum(v[i]))
_name += (v[i] | );
else
_name += v[i];
}
}
string name;
string _name;
int score;/**< 总得分 */
int in;/**< 进球 */
int out;/**< 对方进球 */
int win;/**< 赢得场数 */
int con;/**< 参加比赛次数 */
int tie;/**< 平局次数 */
int lose;/**< 输的次数 */
bool operator < (const snode &b)const
{
if (score == b.score)
{
if (win == b.win)
{
int ta = in - out, tb = b.in - b.out;
if (ta == tb)
{
if (in == b.in)
{
if (con == b.con)
{
return _name < b._name;
}
return con < b.con;
}
return in > b.in;
}
return ta > tb;
}
return win > b.win;
}
return score > b.score;
}
friend istream &operator >> (istream &in, snode &v)
{
string tmp;
getline(in, tmp);
v = tmp;
return in;
} friend ostream &operator << (ostream &out, const snode &v)
{
cout<<v.name<<' '<<v.score<<"p, "<<v.con<<"g ("<<v.win<<'-'<<v.tie<<'-'<<v.lose<<"), ";
cout<<v.in - v.out<<"gd ("<<v.in<<'-'<<v.out<<')';
return out;
} bool operator == (const snode &v)
{
return name == v.name;
}
}a[];
int n, t, g; int find_str(string v)
{
for (int i = ; i < t; i++)
if (a[i] == v)
return i;
return -;
} void fun(string v)
{
int i = -;
while (v[++i] != '#');
string s1(v.begin(), v.begin() + i);
/**< 数字处 */
int t1 = v[++i] - '';
if (isdigit(v[++i]))/**< 第二个是不是数字 */
t1 = * t1 + (v[i++] - '');
int t2 = v[++i] - '';
if (isdigit(v[++i]))/**< 第二个是不是数字 */
t2 = * t2 + (v[i++] - '');
string s2(v.begin() + i + , v.end());
int p1 = find_str(s1), p2 = find_str(s2);
//cout<<p1<<p2<<endl;
if (t1 > t2)/**< 1赢 */
{
a[p1].win++;
a[p2].lose++;
a[p1].score += ;
}
else
if (t1 == t2)/**< 平 */
{
a[p1].tie++;
a[p2].tie++;
a[p1].score++;
a[p2].score++;
}
else/**< 2赢 */
{
a[p2].win++;
a[p1].lose++;
a[p2].score += ;
}
a[p1].con++;
a[p2].con++;
a[p1].in += t1;
a[p2].in += t2;
a[p1].out += t2;
a[p2].out += t1;
} int main()
{
int i, j;
cin>>n;
cin.get();
string st;
while (n--)
{
getline(cin, st);
cout<<st<<endl;
cin>>t;
cin.get();
for (i = ; i < t; i++)
cin>>a[i];
cin>>g;
cin.get();
for (i = ; i < g; i++)
{
getline(cin, st);
fun(st);
}
sort(a, a + t);
for (i = ; i < t; i++)
{
cout<<i + <<") "<<a[i]<<endl;
}
if (n)
cout<<endl;
}
return ;
}

755 - 487--3279

#include <iostream>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map> using namespace std;
int ls[] =
{
, , , , , , , , , ,
, , , , , , , , , ,
, , , , ,
};
char get(char ch)
{
return ls[ch - 'A'] + '';
} map<string, int> mp;
int main()
{
int t, n, i, tag;
cin>>t;
char ch;
string tmp;
while (t--)
{
mp.clear();
cin>>n;
cin.get();
for (i = ; i < n; i++)
{
tmp.clear();
while (ch = cin.get(), ch != '\n')/**< 对输入进行处理换成全数字的字符串 */
{
if (isdigit(ch))
{
tmp += ch;
continue;
}
if (isalpha(ch))
{
tmp += get(ch);
continue;
}
}
mp[tmp]++;/**< 对应字符串个数加1 */
}
tag = true;
for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it)
{
if (it->second > )
{
tmp = it->first;
tmp.insert(tmp.begin() + , '-');
cout<<tmp<<' '<<it->second<<endl;
tag = false;
}
}
if (tag)
cout<<"No duplicates."<<endl;
if (t)
cout<<endl; }
return ;
}

10785 - The Mad Numerologist

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iomanip>
#include <cctype>
#include <climits>
#include <algorithm>
#include <map>
#include <set> using namespace std;
map<char, int> mp1, mp2;
char s1[] =
{
'J', 'S', 'B', 'K', 'T', 'C', 'L', 'D', 'M', 'V',
'N', 'W', 'F', 'X', 'G', 'P', 'Y', 'H', 'Q', 'Z',
'R'
};
char s2[] =
{
'A' , 'U', 'E', 'O', 'I'
};
int n1, n2, p1, p2;
void fun1()
{
while (n1 > )
{
p1++;
if (n1 >= )
mp1[s1[p1]] = ;
else
mp1[s1[p1]] = n1;
n1 -= ;
}
}
void fun2()
{
while (n2 > )
{
p2++;
if (n2 >= )
mp2[s2[p2]] = ;
else
mp2[s2[p2]] = n2;
n2 -= ;
}
}
void print()
{
int i;
string s1, s2;
s1.clear();
s2.clear();
for (map<char, int>::iterator it = mp1.begin(); it != mp1.end(); ++it)
{
for (i = it->second; i > ; i--)
s1 += it->first;
}
for (map<char, int>::iterator it = mp2.begin(); it != mp2.end(); ++it)
{
for (i = it->second; i > ; i--)
s2 += it->first;
}
i = ;
while (s1[i] && s2[i])
{
cout<<s2[i]<<s1[i];
i++;
}
if (s2[i])
cout<<s2[i];
cout<<endl;
}
int main()
{
int m, n, t = ;
cin>>m;
while (m--)
{
cout<<"Case "<<t++<<": ";
cin>>n;
p1 = p2 = -;
n1 = n / ;
n2 = n1 + (n & );
mp1.clear();
mp2.clear();
fun1();
fun2();
print();
}
return ;
}

最新文章

  1. Android—简单的仿QQ聊天界面
  2. sqlserver2008 R2 创建作业(定时任务)
  3. ubuntu下配置apache2多域名(apache2.4.6)
  4. Extended Data Type Properties [AX 2012]
  5. SQL中存储过程的例子
  6. Android学习路径图
  7. ubuntu12.04下编译chrome
  8. hackerrank Ticket
  9. 【mysql】mysql内置函数
  10. LeetCode 542. 01 Matrix
  11. Android为TV端助力 转载:RecyclerView分页加载
  12. [HTTP]POST报文中Content-Type对正文解析的影响
  13. 美化博客CSS
  14. ARDUINO入门按键通信试验
  15. python安装pyMysql
  16. Visual Studio 2017各版本安装包离线下载、安装全解析
  17. 洛谷 P1490 买蛋糕 解题报告
  18. Arraylist集合遍历输出
  19. 折腾了好久的地图缩放 ngui 各种偷懒实现
  20. 【Insert】使用java对mysql数据库进行插入操作

热门文章

  1. SpringMVC分页查询无法直接将对象转换成json的解决办法(报org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type:错)
  2. 暴力(判凸四边形) FZOJ 2148 Moon Game
  3. BFS(最短路) HDOJ 4308 Saving Princess claire_
  4. iOS9导入高德地图报错App Transport Security has blocked...
  5. Python 相关疑问
  6. 172 Factorial Trailing Zeroes 阶乘后的零
  7. Android开发学习——ButterKnife使用
  8. laravel 淘宝 NPM 镜像
  9. [BZOJ1025][SCOI2009]游戏 DP+置换群
  10. QT入门学习