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 ...
随机推荐
- .Net C# RSA签名和验签重写
namespace com._80community.unittest.CUP { /// <summary> /// CUP Client /// </summary> pu ...
- 【原创】大叔问题定位分享(36)openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil
openresty(nginx+lua)中获取不到post数据,ngx.req.get_body_data返回nil This function returns nil if the request ...
- python中的not的意思
python中的not的意思 在python中,not是逻辑判断,用于布尔值true和false,not true是false,not false是true.以下是not的一些常见用法:(1)当表达式 ...
- 使用LEANGOO泳道
转自:https://www.leangoo.com/leangoo_guide/leangoo_yongdao.html 列表使用纵向的纬度管理卡片,通常代表卡片的工作的不同阶段,或者任务的状态.泳 ...
- 使用代码将github仓库里某个issue同步到CSDN博客上
我是一个懒惰的程序员.我在github仓库里用issue的方式写了很多分享文章,想同步到CSDN上.但是我又不想一篇篇手动复制粘贴,因此想用代码来实现自动化. 例子: https://github.c ...
- 7.Spring整合Hibernate_1
Spring 整合 Hibernate 1.Spring指定 database,给下面创建的 SessionFactory用 <!-- !!!!!可以使用 @Resource 将 这个bean对 ...
- impala 建表时报错,不支持中文
1.错误信息 (1366, "Incorrect string value: '\\xE6\\x8E\\x88\\xE6\\x9D\\x83...' for column 'search' ...
- java——多线程—启动线程
继承Thread启动线程 package com.mycom.继承Thread启动线程; /** * * 继承Thread类启动线程的步骤 * 1.定义自定义线程类并继承Thread * 2.重写ru ...
- 5.caffe图片分类流程
一次创建下列文件: 1,create_txt.sh (create_filelist.sh) 2,create_lmdb.sh 3,make_mean.sh 4,train.prototxt+val. ...
- 【LOJ6671】EntropyIncreaser 与 Minecraft
Orz lbt Description https://loj.ac/problem/6671 Solution