CodeForces 221(div 2)
2024-09-17 09:30:49
A
无trick水题。。。
/*
* Author: Plumrain
* Created Time: 2013-12-24 22:26
* File Name: B.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <ctime>
#include <utility> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define INF 999999999999999999
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; inline int Mymod (int a, int b) {int x=a%b; if(x<) x+=b; return x;} int ru[], chu[]; int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
// std::ios::sync_with_stdio(false);
int n, m;
while (scanf ("%d%d", &n , &m) != EOF){
int t1, t2, w;
clr0 (chu); clr0 (ru);
for (int i = ; i < m; ++ i){
scanf ("%d%d%d", &t1, &t2, &w);
chu[--t1] += w;
ru[--t2] += w;
}
int ans = ;
for (int i = ; i < n; ++ i)
ans += abs(chu[i] - ru[i]);
printf ("%d\n", ans / );
}
return ;
}
B
YY题。。。结论直接看代码就好了。。。比赛的时候YY出了结论算样例算错了,然后就去想别的方法了。。。。。。
/*
* Author: Plumrain
* Created Time: 2013-12-24 22:26
* File Name: B.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <ctime>
#include <utility> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define INF 999999999999999999
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; inline int Mymod (int a, int b) {int x=a%b; if(x<) x+=b; return x;} int ru[], chu[]; int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
// std::ios::sync_with_stdio(false);
int n, m;
while (scanf ("%d%d", &n , &m) != EOF){
int t1, t2, w;
clr0 (chu); clr0 (ru);
for (int i = ; i < m; ++ i){
scanf ("%d%d%d", &t1, &t2, &w);
chu[--t1] += w;
ru[--t2] += w;
}
int ans = ;
for (int i = ; i < n; ++ i)
ans += abs(chu[i] - ru[i]);
printf ("%d\n", ans / );
}
return ;
}
C
题意:给一个很大的数m,这个数的各个位上的数字中一定含有至少1个1,6,8,9。你可以重新组织所有数字的顺序,使得重新排列之后的数能被7整除。10^4 <= m <= 10^(10^6)。
注意,排列之后的数不能含有前导0。
解法:把1,6,8,9四个数字放在最后面,根据前面的数*10000除以7的余数,来决定1,6,8,9四个数字的排列顺序即可。至于有没有前导0,特殊处理一下即可。
tag:math, think
/*
* Author: Plumrain
* Created Time: 2013-12-25 14:09
* File Name: C.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <ctime>
#include <utility> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define INF 999999999999999999
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; inline int Mymod (int a, int b) {int x=a%b; if(x<) x+=b; return x;} bool del[];
string temp = "";
map<int, string> mp; void gao(string s)
{
stringstream stm(s);
int num; stm >> num;
int yu = num % ;
if (!mp.count(yu)) mp[yu] = s;
} int main()
{
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
// std::ios::sync_with_stdio(false);
mp.clear();
string tt = "";
gao(tt);
while (next_permutation(tt.begin(), tt.end())) gao(tt); string s;
while (cin >> s){
clr0 (del);
string ss; ss.clear();
int n = sz(s), cnt = ;
for (int i = ; i < n; ++ i){
if (s[i] == ''){
++ cnt; continue;
}
bool ok = ;
for (int j = ; j < ; ++ j) if (s[i] == temp[j] && !del[j]){
del[j] = ; ok = ;
}
if (!ok) ss.pb (s[i]);
} int len = sz(ss);
if (!len){
ss = mp[];
for (int i = ; i < cnt; ++ i) ss.pb ('');
cout << ss << endl;
continue;
}
for (int i = ; i < cnt; ++ i) ss.pb ('');
len = sz(ss);
int flag = ;
for (int i = ; i < len; ++ i)
flag = (flag* + ss[i] - '') % ;
flag = flag * % ;
ss += mp[( - flag) % ];
cout << ss << endl;
}
return ;
}
D
题意:有一个0,1矩阵(最大5000*5000),你可以无限次数地交换任意两行的位置。求交换之后,单个只含有1的矩形的面积最大,并返回这个面积值。
解法:枚举矩形的左下角是从哪一列开始,统计每一行从这一列开始连续的1有多少个记录在num数组里,然后从大到小遍历num数组,并更新面积值即可。
tag:dp, think, good
/*
* Author: Plumrain
* Created Time: 2013-12-26 12:49
* File Name: D.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <ctime>
#include <utility> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(t) t.begin(),t.end()
#define INF 999999999999999999
#define zero(x) (((x)>0?(x):-(x))<eps)
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<a<<" "
#define tst1(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef long long int64; inline int Mymod (int a, int b) {int x=a%b; if(x<) x+=b; return x;} int n, m;
int p[][], num[];
char v[][]; int main()
{
// freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
// std::ios::sync_with_stdio(false);
while (scanf ("%d%d", &n, &m) != EOF){
string s;
for (int i = ; i < n; ++ i)
scanf ("%s", v[i]);
for (int i = ; i < n; ++ i){
int tmp = m;
for (int j = m-; j >= ; -- j){
if (v[i][j] == '')
tmp = j, p[i][j] = j;
else
p[i][j] = tmp;
}
}
int ans = ;
for (int i = ; i < m; ++ i){
clr0 (num);
for (int j = ; j < n; ++ j) num[p[j][i] - i] ++;
int pos = ;
while (pos && num[pos] == ) -- pos;
int cnt = ;
while (pos){
if (num[pos]) cnt += num[pos];
ans = max(cnt*pos, ans);
-- pos;
}
}
printf ("%d\n", ans);
}
return ;
}
最新文章
- android 事件分发机制详解(OnTouchListener,OnClick)
- Codeforces Round #363 (Div. 2)A-D
- ToolBar+DrawerLayout + NavigationView
- MyBatis学习系列一之环境搭建
- 揭开NodeJS的神秘面纱!
- VC编译连接选项详解(转)
- SQL点滴1—SET QUOTED_IDENTIFIER OFF语句的作用
- angularjs的forEach使用
- matlab 子函数的使用
- servlet请求编码与响应编码问题(编码不一致可能会导致乱码)
- 201521123029《Java程序设计》第十一周学习总结
- Android Studio使用过程中遇到的错误
- Network-Emulator&#160;Network-Emulator-Toolkit网络模拟器使用详细介绍
- wordvector to sentence vector
- .NET 托管、非托管、本地:这些代码有什么区别?
- TextView中显示链接 定义颜色
- php webservice实例(转载)
- Linux系统编程--read/write
- freeradius连接mysql数据库慢
- yii2:不使用composer安装yii2-jui的方法