2016 Multi-University Training Contest 2 部分题解
1009,直接贪心,只要让后面的尽量小,第一位和第二位尽量大即可。
1011,直接统计奇数的字母的个数,然后用偶数的个数平均分配到它们上面即可。代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
int odd = , even = ;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int t;
scanf("%d",&t);
if(t % )
{
odd ++;
even += (t - ) / ;
}
else even += t / ;
}
if(odd == )
{
printf("%d\n",even << );
}
else
{
printf("%d\n",even / odd * + );
}
}
}
1001,用二次函数做即可,把阿尔法看做一个未知数。分析过程如下:
代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
ll sum = , sum2 = ;
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
int t;
scanf("%d",&t);
if(t<) t = -t; // 全部值都变正
sum += t;
sum2 += (ll)t*t;
}
sum *= sum;
if(sum == )
{
printf("I64%d/%d\n",sum2,);
continue;
}
ll gd = __gcd(sum,(ll)n);
if(gd > )
{
sum /= gd;
n /= gd;
}
sum2 *= n;
sum2 -= sum;
if(sum2 == )
{
printf("%d/%d\n",,);
continue;
}
gd = __gcd(sum2,(ll)n);
if(gd > )
{
sum2 /= gd;
n /= gd;
}
printf("%I64d/%d\n",sum2,n);
}
}
1012,题意是匹配串和原串去匹配,原串的相应区间可以对某些位置进行操作。设位置x是可以操作的,那么x和它下一个位置进行交换;同时,两个x之间的间隔必须大于等于1。直接暴力即可,代码如下:
#include <bits/stdc++.h>
using namespace std; char s[(int)1e5+],t[+];
char ans[(int)1e5+];
int n,m; bool isok(int pos)
{
int j = ;
for(int i=pos;i<=pos+m-;)
{
if(s[i] == t[j])
{
i++,j++;
}
else
{ if(i == pos+m-) return false;
if(s[i] != t[j+] || s[i+] != t[j]) return false;
else i += ,j += ;
}
}
return true;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
scanf("%s",s+);
scanf("%s",t+);
for(int i=;i<=n;i++) ans[i] = '';
for(int i=;i+m-<=n;i++)
{
if(isok(i)) ans[i] = '';
else ans[i] = '';
}
for(int i=;i<=n;i++)
{
printf("%c",ans[i]);
}
puts("");
}
}
1005,找出共线的点的集合(集合内点的个数大于等于2,可以是重点)。最初的做法是,找出所有的直线方程,统计这上面的点的个数,然后这条线上的集合的个数就是C(2,m)+C(3,m)+...+C(m,m) = 2^m - m - 1。但是我们实现用了大量的map,可能是因为这一点,超时了。TLE的代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include <map>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = (int)1e9 + ;
//const ll p = 257; struct line
{
ll a,b,c;
bool operator <(const line & A) const
{
return a==A.a? b==A.b?c<A.c:b<A.b :a<A.a;
}
};
struct point
{
ll x,y;
bool operator < (const point & A) const
{
return x==A.x ? y<A.y :x<A.x;
} }p[+]; ll qpow(ll x,ll y)
{
ll ans = ;
while(y)
{
if(y&) ans = ans * x % mod;
y >>= ;
x = (x*x) % mod;
}
return ans;
} map<line,ll> M;
map<point,ll> M2;
map<line,ll> M3;
//set<point> S; bool isequel(point a,point b)
{
if(a.x==b.x && a.y==b.y) return ;
return ;
} void get(ll &a,ll &b,ll &c,point p1,point p2)
{
ll x1 = p1.x,y1 = p1.y;
ll x2 = p2.x,y2 = p2.y;
c = x1 - x2;
a = y1 - y2;
b = x1*y2-y1*x2;
} ll getn(ll now)
{
for(ll i = ;;i++)
{
if(i*(i+)/ == now) return i+;
}
} void modify(ll& a , ll & b, ll &c)
{
if(a== && b == ) {c=;return;}
if(b== && c == ) {a=;return;}
if(a== && c == ) {b=;return;}
if(a && b && c)
{
int gd = __gcd(a,__gcd(b,c));
a /= gd;
b /= gd;
c /= gd;
}
else
{
if(a==)
{
int gd = __gcd(b,c);
b /= gd;
c /= gd;
}
else if(b==)
{
int gd = __gcd(a,c);
a /= gd;
c /= gd;
}
else if(c==)
{
int gd = __gcd(a,b);
a /= gd;
b /= gd;
}
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
M.clear();
M2.clear();
M3.clear();
//S.clear();
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
ll x,y;
scanf("%I64d%I64d",&x,&y);
p[i] = (point){x,y};
M2[p[i]] ++;
} for(map<point,ll>::iterator it=M2.begin();it!=M2.end();it++)
{
map<point,ll>::iterator it2 = it;
it2++;
for(;it2!=M2.end();it2++)
{
//if(isequel((*it).first,(*it2).first)) continue;
ll a,b,c;
get(a,b,c,(*it).first,(*it2).first);
modify(a,b,c);
M[(line){a,b,c}] += (*it).second + (*it2).second;
M3[(line){a,b,c}] ++;
//S.insert(p[i]);
//printf("%d %d %d !!\n",i,j,M[(line){a,b,c}]);
}
} ll ans = ; for(map<line,ll>::iterator it = M.begin();it!=M.end();it++)
{
ll nownow = (*it).second;
//cout << now <<"!!"<<endl;
//ll n = now / 2;
map<line,ll>::iterator itt = M3.find((*it).first);
ll now = ((*itt).second);
//ll now = M3.second;
ll n = getn(now);
ll nn = nownow/(n-);
ans += (qpow(,nn)-nn-);
ans %= mod;
}
for(map<point,ll>::iterator it = M2.begin();it!=M2.end();it++)
{
ll now = (*it).second;
if(now<=) continue;
ans += (qpow(,now)-now-);
} cout << ans <<endl; }
return ;
} /* 5
0 1
0 0
0 0
0 1
0 2
*/
看了标程以后觉得他的方法很好。大概是这样子的:先对所有的点按照x,y的大小排序,然后对每一个点,算出包含了这个点的的集合的个数。具体见代码和注释:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = + ;
const int mod = (int)1e9 + ; struct point
{
int x, y;
point() {}
point(int _x, int _y): x(_x), y(_y) {}
point operator - (const point & temp) const
{
return point(x - temp.x, y - temp.y);
}
bool operator < (const point & temp) const
{
return x < temp.x || (x == temp.x && y < temp.y);
}
bool operator == (const point & temp) const
{
return x == temp.x && y == temp.y;
}
void reduce()
{
int g = __gcd(abs(x), abs(y));
if(g) {x /= g; y /= g;}
}
} p[N], Q[N]; int pw[N];
void init()
{
pw[] = ;
for(int i = ; i < N; i++) pw[i] = pw[i-] * % mod;
} void update(int &x, int y)
{
x += y;
if(x >= mod) x -= mod;
} void run()
{
int n;scanf("%d", &n);
int ans = ;
for(int i = ; i <= n; i++) scanf("%d%d",&p[i].x, &p[i].y);
// 先要对所有点排序,不然共线向量会有正负的区别
sort(p + , p + + n);
for(int i = ; i <= n; i++)
{
int cnt = , tot = ;
// cnt 是除了i这个点以外的重点的个数
// m是 这个点位置以外的点的个数
for(int j = i + ; j <= n; j++)
{
if(p[i] == p[j]) cnt++;
else Q[++tot] = p[j] - p[i]; // Q 放的是向量
}
update(ans, pw[cnt] - ); // 这里是对重点们形成集合的贡献
// 计算方式是选出i这个点,之后从剩下的cnt这么多个点中选出至少一个的种类数
// 那么,贡献就是C(1,cnt)+C(2,cnt)+...+C(cnt,cnt) = 2^cnt - 1 for(int j = ; j <= tot; j++) Q[j].reduce();
sort(Q + , Q + + tot);
for(int x = , y; x <= tot; x = y)
{
for(y = x; y <= tot && Q[x] == Q[y]; y++) ;
// y 出来的时候已经是 Q[x] != Q[y] 了,因此 y-x 正好是这一个角度上其他的点的个数
// 这时候,对答案的贡献是,从除了i这个点以外的重点中选出任意个数的点的种类数
// 和从这个角度上的其他点中选出至少1个点的种类数的乘积
update(ans, 1LL * pw[cnt] * (pw[y - x] - ) % mod);
}
}
printf("%d\n", ans);
} int main()
{
init();
int T;scanf("%d", &T);
while(T--) run();
return ;
}
2016 Multi-University Training Contest 2 部分题解的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2016 Multi-University Training Contest 3 部分题解
1001,只要枚举区间即可.签到题,要注意的是输入0的话也是“TAT”.不过今天补题的时候却WA了好几次,觉得奇怪.原来出现在判断条件那里,x是一个int64类型的变量,在进行(x<65536* ...
- 2016 Multi-University Training Contest 1 部分题解
第一场多校,出了一题,,没有挂零还算欣慰. 1001,求最小生成树和,确定了最小生成树后任意两点间的距离的最小数学期望.当时就有点矛盾,为什么是求最小的数学期望以及为什么题目给了每条边都不相等的条件. ...
- 2016 Multi-University Training Contest 4 部分题解
1001,官方题解是直接dp,首先dp[i]表示到i位置的种类数,它首先应该等于dp[i-1],(假设m是B串的长度)同时,如果(i-m+1)这个位置开始到i这个位置的这一串是和B串相同的,那么dp[ ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- 2016 Al-Baath University Training Camp Contest-1 F
Description Zaid has two words, a of length between 4 and 1000 and b of length 4 exactly. The word a ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016 Al-Baath University Training Camp Contest-1 I. March Rain —— 二分
题目链接:http://codeforces.com/problemset/gymProblem/101028/I I. March Rain time limit per test 2 second ...
- 2018 Multi-University Training Contest 3(部分题解)
Problem F. Grab The Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Ja ...
随机推荐
- C语言存30位数字长的十进制方法
题目:将一个长度最多为30位数字的十进制非负整数转换为二进制数输出. 首先: 1,30位数字的十进制,并没有一个数据类型可以存下30位的整数类型数字,所以考虑用字符串存储这个数据,遍历这个字符串,每个 ...
- gdb-example-ncurses
gdb-example-ncurses http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html 1. The Prob ...
- JS基础_变量的声明提前、函数的声明提前
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Category VS Extension 原理详解
(一)Category 1.什么是Category? category是Objective-C 2.0之后添加的语言特性,别人口中的分类.类别其实都是指的category.category的主要作用是 ...
- Linux下创建NFS来实现共享文件
简介说明: 在项目生产环境我们经常需要实现文件共享,传统的常见方案是通过NFS,实现服务器之间共享某一块磁盘,通过网络传输将分散的文件集中存储在一块指定的共享磁盘,实现基本的文件共享.实现这种方案,分 ...
- android提升
https://blog.csdn.net/lou_liang/article/details/82856531
- (备忘)Eclipse设置:背景与字体大小和xml文件中字体大小调整
Eclipse中代码编辑背景颜色修改: 1.打开window / Preference,弹出Preference面板 2.展开General标签,选中Editors选项,展开. 3.选中 Text ...
- 【linux】ubuntu修改系统时间
ubuntu修改时间步骤 ① 先把系统校验时间的程序停止掉 /lib/systemd/systemd-timesyncd systemd 开始,包括了一个名为systemd-timesyncd 的守护 ...
- 团队第三次作业:Alpha版本第一周小结
姓名 学号 周前计划安排 每周实际工作记录 自我打分 XXX 061109 1.原型设计与编码任务分配 2.构思程序个性化测试模块的初步实现 1.原型设计与编码任务分配 2.设计了部分类及其成员函数( ...
- 顺丰科技面试-java开发
顺丰科技的面试官感觉人都挺随和,总共经历三面,两轮技术面,一轮hr面. 一.专业面一 主要是对着我的简历上的东西问,我的一个项目经历,两个实习上面以及自己提到会的技能展开的提问. (1)自我简介 (2 ...