B. So You Think You Can Count?

设dp[i]表示以i为结尾的方案数,每个位置最多往前扫10位

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
const int mod = 1e9+;
ll dp[maxn];//dp[i]表示以i结尾的方案数。
int num[];
char s[maxn];
int main()
{
int n;
cin >> n;
cin >> s + ;
dp[] = ;
for(int i = ;i <= n;i++)
{
memset(num, ,sizeof(num));
for(int j = i;j > ;j--)
{
num[s[j]-'']++;
if(num[s[j]-''] > ) break;
dp[i] = (dp[i] + dp[j-])%mod;
}
}
cout << dp[n] << endl;
return ;
}

C. MRT Map

思路:存下每个字符串26个字母出现的次数,然后建边的时候计算一遍权值,然后dijkstra就好了。

 #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
const int maxn = 5e5 + ;
const int INF = 0x3f3f3f3f;
int n, m;
int num[maxn][];
int cal(int u, int v)
{
int ans = ;
for(int i = ;i < ;i++){
if(num[u][i] && num[v][i])
ans++;
}
return ans;
}
struct edge{
int to;
int cost;
}e;
vector <edge> G[maxn];
int d[maxn];
void add(int u, int v)
{
e.to = v;
e.cost = cal(u,v);
G[u].push_back(e);
}
void dijkstra(int s)
{
priority_queue<P,vector<P>,greater<P> > que;
fill(d ,d + n + ,INF);
d[s] = ;
que.push(P(,s));
while(!que.empty())
{
P p= que.top();que.pop();
int v = p.second;
if(d[v] < p.first) continue;
for(int i = ;i < G[v].size();i++)
{
edge e = G[v][i];;
if(d[e.to] > d[v] +e.cost)
{
d[e.to]= d[v] + e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> n >> m;
string a;
for(int i = ;i <= n;i++)
{
cin >> a;
int len = a.size();
for(int j = ;j < len;j++){
if(a[j] >= 'a' && a[j] <= 'z') num[i][a[j] - 'a']++;
else num[i][a[j] - 'A']++;
} }
for(int i = ;i <= m;i++)
{
int u, v;
cin >> u >> v;
add(u, v);
add(v, u);
}
int s, t;
cin >> s >> t;
dijkstra(s);
cout << d[t] << endl;
return ;
}

D. Husam's Bug跑

签到题1

 #include<bits/stdc++.h>
using namespace std;
int main()
{
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--)
{
string s;
int cnt = , num = , sum = ;//字母 数字 特殊符号
cin >> s;
for(int i = ;i < s.size();i++)
{
if(s[i] >= 'a' && s[i] <= 'z') cnt++;
if(s[i] >= 'A' && s[i] <= 'Z') cnt++;
if(s[i] >= '' && s[i] <= '') num++;
if(s[i] == '@' || s[i] == '?' || s[i] == '!') sum++;
}
if(cnt < ){
cout << "The last character must be a letter." << endl;
}
else if(num < ){
cout << "The last character must be a digit." << endl;
}
else if(sum < ){
cout << "The last character must be a symbol." << endl;
}
else cout << "The last character can be any type." << endl;
}
return ;
}

E. Abdalrahman Ali Bugs

思路:容易得出X是在 2 - 最大出现次数之间,直接暴力枚举所有答案取最优解。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num[];
ll check(ll x)
{
ll ans = ;
for(int i = ;i < ;i++){
ans += (num[i] % x) * num[i];
}
return ans;
}
int main()
{
std::ios::sync_with_stdio(false);
string a;
cin >> a;
ll mx = ;
for(int i = ;i < a.size();i++)
{
int t = a[i] - 'a';
num[t]++;
mx = max(num[t],mx);
}
ll x = ;
ll ans = check(x);
for(ll i = ;i <= mx;i++){
if(check(i) < ans){
x = i;
ans = check(i);
}
}
cout << x << endl;
return ;
}

F. Certifications

思路:在a数组中二分一个大于X的最小值,找不到则输出那一串。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
ll a[maxn];
const ll INF = 1e18;
int main()
{
std::ios::sync_with_stdio(false);
int n, m;
cin >> n;
for(int i = ;i < n;i++){
cin >> a[i];
}
sort(a, a + n);
a[n] = INF;
cin >> m;
while(m--)
{
int x;
cin >> x;
int l = , r = n, o = ;
while(l <= r){
int mid = (l + r) / ;
if(a[mid] >= x) r = mid - , o = mid;
else l = mid + ;
// cout << o << endl;
}
if(a[o] == INF) cout << "Dr. Samer cannot take any offer :(." << endl;
else cout << a[o] << endl;
}
return ;
}

G. In the Chairman's office

qaq签到题2。


H. Give Me This Pizza

思路:右边最近的较大值,这不是很白的一个单调栈么,暑假队内赛第一场的A,相似度80%。

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
int st[maxn], ans[maxn], a[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int n;
cin >> n;
memset(ans,-,sizeof(ans));
for(int i = ;i < n;i++) cin >> a[i];
int cnt = ;
for(int i = ;i < n;i++)
{
while(cnt > && a[st[cnt]] < a[i]){
ans[st[cnt--]] = i;
}
st[++cnt] = i;
}
for(int i = ;i < n;i++){
if(ans[i] == -) cout << ans[i] << " ";
else cout << a[ans[i]] << " ";
}
return ;
}

I. Husam and the Broken Present 1

思路:对角线元素是平方和,对其开根号即可。

 #include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
int ans[maxn];
int main()
{
std::ios::sync_with_stdio(false);
int n;
cin >> n;
int a;
for(int i = ;i < n;i++){
for(int j = ;j < n;j++){
cin >> a;
if(i == j) ans[i] = sqrt(a);
}
}
for(int i = ;i < n;i++){
if(i == n - ) cout << ans[i] << endl;
else cout << ans[i] << " ";
}
return ;
}

K.Counting Time

思路:可以很暴力的一道题,9!枚举出3*3矩阵所有状态,判断和题目所给的矩阵非0位相不相等并且满不满足题意。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mp[][];
int mp2[][];
int a[];
int vis[];
int ans;
int dx[] = {, , , -, , , -, -};
int dy[] = {-, , , , -, , , -}; bool check(int x, int y){
if(x >= && x < && y >= && y < ) return true;
else return false;
}
bool check1(int x, int y,char val)
{
if(mp2[x][y] == ) return true;
for(int i = ;i < ;i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if(check(nx, ny) && mp2[nx][ny] == val + ) return true;
}
return false;
}
bool check3(){
for(int i = ;i < ;i++){
for(int j = ;j < ;j++){
if(!check1(i, j, mp2[i][j])) return false;
}
}
return true;
}
int check2()
{
for(int i = ;i < ;i++){
int x = i / ;
int y = i % ;
mp2[x][y] = a[i];
if(mp[x][y] != a[i] && mp[x][y] != ) return ;
}
if(check3()) return ;
else return ;
}
void dfs(int pos)
{
if(pos >= ){
ans += check2();
return;
}
for(int i = ;i <= ;i++)
{
if(!vis[i]) {
a[pos] = i;
vis[i] = ;
dfs(pos + );
vis[i] = ;
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
char c;
for(int i = ;i < ;i++){
for(int j = ;j < ;j++)
{
cin >> c;
int t = c - '';
mp[i][j] = t;
}
}
dfs();
cout << ans << endl;
return ;
}

2017 JUST Programming Contest 2.0的更多相关文章

  1. 2017 JUST Programming Contest 2.0 题解

    [题目链接] A - On The Way to Lucky Plaza 首先,$n>m$或$k>m$或$k>n$就无解. 设$p = \frac{A}{B}$,$ans = C_{ ...

  2. gym101532 2017 JUST Programming Contest 4.0

    台州学院ICPC赛前训练5 人生第一次ak,而且ak得还蛮快的,感谢队友带我飞 A 直接用claris的模板啊,他模板确实比较强大,其实就是因为更新的很快 #include<bits/stdc+ ...

  3. 2017 JUST Programming Contest 3.0 B. Linear Algebra Test

    B. Linear Algebra Test time limit per test 3.0 s memory limit per test 256 MB input standard input o ...

  4. 2017 JUST Programming Contest 3.0 I. Move Between Numbers

    I. Move Between Numbers time limit per test 2.0 s memory limit per test 256 MB input standard input ...

  5. 2017 JUST Programming Contest 3.0 D. Dice Game

    D. Dice Game time limit per test 1.0 s memory limit per test 256 MB input standard input output stan ...

  6. 2017 JUST Programming Contest 3.0 H. Eyad and Math

    H. Eyad and Math time limit per test 2.0 s memory limit per test 256 MB input standard input output ...

  7. 2017 JUST Programming Contest 3.0 K. Malek and Summer Semester

    K. Malek and Summer Semester time limit per test 1.0 s memory limit per test 256 MB input standard i ...

  8. 2017 JUST Programming Contest 3.0 E. The Architect Omar

    E. The Architect Omar time limit per test 1.0 s memory limit per test 256 MB input standard input ou ...

  9. gym101343 2017 JUST Programming Contest 2.0

    A.On The Way to Lucky Plaza  (数论)题意:m个店 每个店可以买一个小球的概率为p       求恰好在第m个店买到k个小球的概率 题解:求在前m-1个店买k-1个球再*p ...

随机推荐

  1. 2019Flutter面试题最新整理大全(含答案)

    一.前言2019年行将结束,也该规划一下自己的职业生涯了:是选择继续从事Android(Android的话已经火了几年了,现在算是进入寒冬了,需要考虑清楚)?还是学习新的跨平台开发Flutter技术? ...

  2. [HDU 3625]Examining the Rooms (第一类斯特林数)

    [HDU 3625]Examining the Rooms (第一类斯特林数) 题面 有n个房间,每个房间有一个钥匙,钥匙等概率的出现在n个房间内,每个房间中只会出现且仅出现一个钥匙.你能炸开门k次, ...

  3. 学习servlet时出现的一些问题

    此篇用来记录学习servlet时遇到的一些问题,谨防以后再犯. 问题1.导入的web项目,servlet中导入的包名报错. (1)缺少相关包,推荐一个网站下载jar包很方便http://mvnrepo ...

  4. tornado后台小框架

    import tornado.ioloop import tornado.web """使用get方法提交过来数据就是用get方法,使用post执行post方法这个框架的 ...

  5. js 柯里化、深拷贝、浅拷贝

    curry const sum = (a, b, c, d) => a + b + c + d const curry = fn => (judge = (...args) => a ...

  6. windos忘记密码登陆如何修复

    一.简单的方法: 开机启动windows,进入欢迎界面后,会出现输入用户名密码提示框,这时候,同时按住Ctrl+Alt+Delete,会跳出一个账号窗口,输入用户名:administer,按回车即可. ...

  7. cgi+lighttpd上传大文件失败解决办法

    问题: - 前端页面点击上传按钮,不超过30M的小文件顺利上传到板子指定位置,上传60Md的更新包,出错,http状态码413——请求实体过大 环境: - web服务器——lighttpd1.4.30 ...

  8. XMPP即时通讯协议使用(一)——Openfire安装

    Openfire服务器安装 下载地址:https://www.igniterealtime.org/downloads/index.jsp,根据你的操作系统,选择对应的下载版本.本文选择的是openf ...

  9. MySQL 授权用户 ; 存储过程的DEFINER; 命令分隔符DELIMITER

    最近项目中遇到有人使用DEFINER这样的关键字,找了半天没有怎么理解这个意思.以为是限制谁使用这个存储过程,后来测试发现并不是这样. 搜索网上发现很多说法都不正确.看到一篇博客,做了如下介绍,才有所 ...

  10. simple_pt时遇到的问题

    elf.c:30:18: fatal error: gelf.h: No such file or directory 安装libelf-dev 遇到找不到ldwarf apt-cache  sear ...