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. python——datetime模块

    一.datetime模块介绍 (一).datetime模块中包含如下类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间对象 datetime 日期时 ...

  2. ADC(简易的DMA传输)的认识

    ADC(简易的DMA传输)的认识 首先看到是ADC的特性 1.ADC的12位分辨率.不能直接测量负电压,然后是最小量程化单位是LSB=Vref+/212 2.单次和转换模式的使用 3. 从通道0到通道 ...

  3. 如何做PPT

    如何做出更漂亮的PPT? 1.文字对齐,PPT字体最好使用微软雅黑,文档最好使用宋体 2.总分总的叙述形式 3.颜色最好使用冷色系,蓝色.灰色.灰蓝色等等 4.每段话中的重点内容标出特殊颜色 5.可使 ...

  4. upx压缩notepad.exe(运行时压缩)

    PEView:https://www.lanzous.com/i5k9vbg UPX:https://www.lanzous.com/i5k9vch notepad.exe:https://www.l ...

  5. 一键部署YApi

    编写docker-compose.yml version: '2.1' services: yapi: image: mrjin/yapi:latest # build: ./ container_n ...

  6. 如何在C#中使用sqlite,一个简单的类

    </pre><pre name="code" class="csharp"> using System.Collections.Gene ...

  7. RabbitMQ ——整体架构

    一 .概述 从整体上讲Rabbitmq就是一个生产者消费者的模型. 我们将中间的整个broker就当做是一个消息中间件的实体就可以了. 单从这个方面上讲,生产者发送消息到broker上面,然后消费者从 ...

  8. 2018-2-13-win10-uwp-分治法

    title author date CreateTime categories win10 uwp 分治法 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:2 ...

  9. 2019-9-8-WPF-渲染原理

    title author date CreateTime categories WPF 渲染原理 lindexi 2019-9-8 10:40:0 +0800 2018-7-15 16:2:47 +0 ...

  10. Android学习电子书