A - Pretty Matrix

DreamGrid's birthday is coming. As his best friend, BaoBao is going to prepare a gift for him.

As we all know, BaoBao has a lot of matrices. This time he picks an integer matrix with  rows and  columns from his collection, but he thinks it's not pretty enough. On the one hand, he doesn't want to be stingy, but some integers in the matrix seem to be too small. On the other hand, he knows that DreamGrid is not good at algebra and hates large numbers, but some integers in the matrix seem to be too large and are not suitable for a gift to DreamGrid.

Based on the above consideration, BaoBao declares that a matrix is pretty, if the following conditions are satisfied:

  1. For every integer  in the matrix, .
  2. For every integer  in the matrix, .

where  is the integer located at the -th row and the -th column in the matrix, and  and  are two integers chosen by BaoBao.

Given the matrix BaoBao picks, along with the two integers  and , please help BaoBao change some integers in the matrix (BaoBao can change an integer in the matrix to any integer) so that the matrix becomes a pretty matrix. As changing integers in the matrix is tiring, please tell BaoBao the minimum number of integers in the matrix he has to change to make the matrix pretty.

Input

There are multiple test cases. The first line of input is an integer  (about 100), indicating the number of test cases. For each test case:

The first line contains four integers , ,  and . (). Their meanings are described above.

For the next  lines, the -th line contains  integers  (), representing the original matrix.

Output

For each test case output one line indicating the answer. If it's impossible to make the matrix pretty, print "No Solution" (without quotes) instead.

Sample Input

2
3 4 2 3
3 2 2 2
2 1 2 3
2 3 100 3
2 1 2 1
1
2

Sample Output

2
No Solution

思路:如果小的大于大的就输出没有解决的,其余的遍历矩阵判断就ok了(签到题之一)

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath> typedef long long ll;
using namespace std;
int a[105][105];
int main()
{
int T;
cin>>T;
while(T--)
{
int n,m,A,B;
ll s=0;
scanf("%d%d%d%d",&n,&m,&A,&B);
if(A>B)
{
for(int t=0;t<n;t++)
{
for(int j=0;j<m;j++)
{
scanf("%d",&a[t][j]);
}
}
printf("No Solution\n");
}
else
{
for(int t=0;t<n;t++)
{
for(int j=0;j<m;j++)
{
scanf("%d",&a[t][j]);
if(a[t][j]>=A&&a[t][j]<=B)
{
continue;
}
else
{
s++;
} }
}
cout<<s<<endl;
}
}
return 0;
}

J - PPAP

"I have a pen. I have an apple. Uh! Applepen."

"I have a pen. I have pineapple. Uh! Pineapplepen."

The above lyrics are taken from PPAP, a single by Pikotaro. It was released as a music video on YouTube on 25 August 2016, and has since become a viral video. As of October 2017, the official video has been viewed over 126 million times.

Let's view this song from a mathematical perspective. In the lyrics there actually hides a function , which takes two lowercased string  and  as the input and works as follows:

  • First, calculate  ( here means string concatenation).
  • Then, capitalize the first character of  to get .
  • Make  as its output, and the function is done.

For example, we have PPAP("pen", "apple") = "Applepen", and PPAP("pen", "pineapple") = "Pineapplepen".

Given two lowercased strings  and , your task is to calculate .

Input

The first line of the input contains an integer  (about 100), indicating the number of test cases. For each test case:

The first and only line contains two strings  and  () separated by one space. It's guaranteed that both  and  consist of only lowercase English letters.

Output

For each test case output one line containing one string, indicating .

思路:按照要求解即可

基本这两道题在10分钟左右可以解决

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath> typedef long long ll;
using namespace std;
int a[105][105];
int main()
{
string str1,str2,str3;
int n;
cin>>n;
for(int t=0;t<n;t++)
{
cin>>str1>>str2;
str2[0]=toupper(str2[0]);
str3=str2+str1;
cout<<str3<<endl;
}
return 0;
}

G - Traffic Light

DreamGrid City is a city with  intersections arranged into a grid of  rows and  columns. The intersection on the -th row and the -th column can be described as , and two intersections  and  are connected by a road if .

At each intersection stands a traffic light. A traffic light can only be in one of the two states: 0 and 1. If the traffic light at the intersection  is in state 0, one can only move from  to  or ; If the traffic light is in state 1, one can only move from  to  or  (of course, the destination must be another intersection in the city).

BaoBao lives at the intersection , and he wants to visit his best friend DreamGrid living at the intersection . After his departure, in each minute the following things will happen in order:

  • BaoBao moves from his current intersection to another neighboring intersection along a road. As a law-abiding citizen, BaoBao has to obey the traffic light rules when moving.
  • Every traffic light changes its state. If a traffic light is in state 0, it will switch to state 1; If a traffic light is in state 1, it will switch to state 0.

As an energetic young man, BaoBao doesn't want to wait for the traffic lights, and he must move in each minute until he arrives at DreamGrid's house. Please tell BaoBao the shortest possible time he can move from  to  to meet his friend, or tell him that this is impossible.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  and  (), indicating the size of the city.

For the following  lines, the -th line contains  integers  (), where  indicates the initial state of the traffic light at intersection .

The next line contains four integers , ,  and  (, ), indicating the starting intersection and the destination intersection.

It's guaranteed that the sum of  over all test cases will not exceed .

Output

For each test case output one line containing one integer, indicating the shortest possible time (in minute) BaoBao can move from  to  without stopping. If it is impossible for BaoBao to arrive at DreamGrid's house, print "-1" (without quotes) instead.

Sample Input

4
2 3
1 1 0
0 1 0
1 3 2 1
2 3
1 0 0
1 1 0
1 3 1 2
2 2
1 0
1 0
1 1 2 2
1 2
0 1
1 1 1 1

Sample Output

3
5
-1
0

Hint

For the first sample test case, BaoBao can follow this path: .

For the second sample test case, due to the traffic light rules, BaoBao can't go from  to  directly. Instead, he should follow this path: .

For the third sample test case, it's easy to discover that BaoBao can only go back and forth between  and .

思路:BFS搜索一下,注意奇偶性建边(之前做过)

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define maxn 100005
using namespace std; struct Node
{
int x,y;
int dis;
};
vector<int> vec[maxn];
vector<bool> book[maxn];
int n,m,sx,sy,ex,ey;
int dirx[]={0,0,-1,1};
int diry[]={-1,1,0,0};
bool judge(int x,int y)
{
if(x<1||x>n||y<1||y>m||book[x][y]) return false;
return true;
}
int bfs()
{
queue<Node> que;
Node start;
start.x=sx;
start.y=sy;
start.dis=0;
que.push(start);
book[sx][sy]=true;
while(!que.empty())
{
start=que.front();
que.pop();
int state=vec[start.x][start.y];
if(start.dis%2)
{
if(state) state=0;
else state=1;
}
if(state==0)
{
Node tmp;
for(int i=2;i<4;i++)
{
tmp.x=start.x+dirx[i];
tmp.y=start.y+diry[i];
tmp.dis=start.dis+1;
if(tmp.x==ex&&tmp.y==ey) return tmp.dis;
if(judge(tmp.x,tmp.y))
{
book[tmp.x][tmp.y]=true;
que.push(tmp);
}
}
}
else
{
Node tmp;
for(int i=0;i<2;i++)
{
tmp.x=start.x+dirx[i];
tmp.y=start.y+diry[i];
tmp.dis=start.dis+1;
if(tmp.x==ex&&tmp.y==ey) return tmp.dis;
if(judge(tmp.x,tmp.y))
{
book[tmp.x][tmp.y]=true;
que.push(tmp);
}
}
}
}
return -1;
}
int main()
{ int T;
cin>>T;
while(T--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
vec[i].clear();
book[i].clear();
}
for(int i=1;i<=n;i++)
{
vec[i].push_back(0);
book[i].push_back(false);
for(int j=1;j<=m;j++)
{
int x;
scanf("%d",&x);
vec[i].push_back(x);
book[i].push_back(false);
}
}
scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
if(sx==ex&&sy==ey) cout<<0<<endl;
else cout<<bfs()<<endl;
}
}

C - Mergeable Stack

Given  initially empty stacks, there are three types of operations:

  • 1 s v: Push the value  onto the top of the -th stack.

  • 2 s: Pop the topmost value out of the -th stack, and print that value. If the -th stack is empty, pop nothing and print "EMPTY" (without quotes) instead.

  • 3 s t: Move every element in the -th stack onto the top of the -th stack in order.

    Precisely speaking, denote the original size of the -th stack by , and the original size of the -th stack by . Denote the original elements in the -th stack from bottom to top by , and the original elements in the -th stack from bottom to top by .

    After this operation, the -th stack is emptied, and the elements in the -th stack from bottom to top becomes . Of course, if , this operation actually does nothing.

There are  operations in total. Please finish these operations in the input order and print the answer for every operation of the second type.

Input

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers  and  (), indicating the number of stacks and the number of operations.

The first integer of the following  lines will be  (), indicating the type of operation.

  • If , two integers  and  (, ) follow, indicating an operation of the first type.
  • If , one integer  () follows, indicating an operation of the second type.
  • If , two integers  and  (, ) follow, indicating an operation of the third type.

It's guaranteed that neither the sum of  nor the sum of  over all test cases will exceed .

Output

For each operation of the second type output one line, indicating the answer.

Sample Input

2
2 15
1 1 10
1 1 11
1 2 12
1 2 13
3 1 2
1 2 14
2 1
2 1
2 1
2 1
2 1
3 2 1
2 2
2 2
2 2
3 7
3 1 2
3 1 3
3 2 1
2 1
2 2
2 3
2 3

Sample Output

13
12
11
10
EMPTY
14
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY

思路,链表的操作,利用STL的list,但是要注意输入输出,去网上学了一下c++的输入输出加速外挂(900+ms险过)

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<list>
#define N 300005 typedef long long ll;
using namespace std; list<int>L[N]; int main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--)
{
for(int i=0; i<N; i++)L[i].clear();
int n,q;
cin>>n>>q;
while(q--)
{
int op;
cin>>op;
if(op==1)
{
int a,b;
cin>>a>>b;
L[a].push_back(b);
}
else if(op==2)
{
int a;
cin>>a;
if(L[a].size())
{
cout<<L[a].back()<<"\n";
L[a].pop_back();
}
else cout<<"EMPTY\n";
}
else
{
int a,b;
cin>>a>>b;
L[a].splice(L[a].end(),L[b]);
}
}
}
return 0;
}

QDU_组队训练(AJFC)的更多相关文章

  1. qdu_组队训练(ABCFIJK)

    A - Second-price Auction Do you know second-price auction? It's very simple but famous. In a second- ...

  2. QDU_组队训练(ABEFGHKL)

    A - Accurately Say "CocaCola"! In a party held by CocaCola company, several students stand ...

  3. 组队训练3回放 ——hnqw1214

    组队训练3回放 练习赛过程回放: 开场先看最后一题, 发现是专题训练时做过的网络流原题, cst照着之前的打一遍,第一遍WA, 发现数组开小了,改大后AC. 这时候qw看B题, 一开始想不到方法, c ...

  4. 组队训练1 回放(转载至cxhscst2's blog)

      第一场组队训练……意料之中的爆炸. 开场先看题,H是斐波那契水题,qw把H切了. 同时czy看I题(排列),cst继续读其他题. czy尝试交I,PE. cst发现K是水题. cst上来敲K,WA ...

  5. 组队训练2 回放(转载至cxhscst2's blog)

    2017/3/4  12:00-17:00 Solve 9 / 13 Penalty 717 练习赛过程回放: 开场5分中J题签到(cst) 12分钟时qw签到A 这时qw继续开写M,WA,检查代码. ...

  6. 【组队训练】2016 ACM/ICPC Asia Regional Dalian Online

    因为不是一队……毫无晋级的压力……反正有压力也进不去呵呵呵…… 开场zr看1006我看1010.. 1010我一直在wa... zr的1006倒是比较轻松的过了...然后我让他帮我看10.... 跟他 ...

  7. 【组队训练】2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest

    好多oj都崩掉了,于是打了cf.. 开始开的最后一题...尼玛题好长终于看完了...神题不会.... I过了好多人..看了下,一眼题...随便敲了下,1A ]; int main(){ int n, ...

  8. 问题 J: Palindromic Password ( 2018组队训练赛第十五场) (简单模拟)

    问题 J: Palindromic Password 时间限制: 3 Sec  内存限制: 128 MB提交: 217  解决: 62[提交][状态][讨论版][命题人:admin] 题目描述 The ...

  9. 问题 C: Frosh Week(2018组队训练赛第十五场)(签到)

    问题 C: Frosh Week 时间限制: 4 Sec  内存限制: 128 MB提交: 145  解决: 63[提交][状态][讨论版][命题人:admin] 题目描述 Professor Zac ...

随机推荐

  1. Python学习笔记_Python向Excel写入数据

    实验环境 1.OS:Win 10 64位 2.Python 3.7 3.如果没有安装xlwt库,则安装:pip install xlwt 下面是从网上找到的一段代码,网上这段代码,看首行注释行,是在L ...

  2. 关闭是否只查看安全传送的网页内容提示框 和 是否允许运行软件,如ActiveX控件和插件提示框

    关闭是否只查看安全传送的网页内容提示框 最新编写 爬虫程序,运行程序后,电脑就总是出现下面这个提示框,一遍遍点"是"或"否"繁琐又麻烦.我看得有点不耐烦了.于是 ...

  3. 如果你的资源贫乏,那么专注做好一件事将是你的唯一出路(no reading yet)

    http://www.jianshu.com/p/8784f0fd7ab8/comments/1161511

  4. JavaEE互联网轻量级框架整合开发(书籍)阅读笔记(2):SSM+Redis概念理解

    一.SSM+Redis的结构图 在Java互联网中,以Spring+SpringMVC+MyBatis(SSM)作为主流框架,SSM+Redis的结构图如下: 二.下面介绍它们各自承担的功能: 1.S ...

  5. c++基础之struct

    就是让用户自己自定义一个要往里面放各种东西的抽屉 // 声明一个结构体类型 Books struct Books { ]; ]; ]; int book_id; }; int main( ) { Bo ...

  6. LibreOJ 6279 数列分块入门 3(分块+排序)

    题解:自然是先分一波块,把同一个块中的所有数字压到一个vector中,将每一个vector进行排序.然后对于每一次区间加,不完整的块加好后暴力重构,完整的块直接修改标记.查询时不完整的块暴力找最接近x ...

  7. sqlTransaction 简单的应用

    sqlTansaction表示要在 SQL Server 数据库中处理的 Transact-SQL 事务 static void Main(strng[] args) { //往数据库里面插入数据 s ...

  8. React + Python 七月小说网 功能设计(二)

    概述 在通过对世面上的各种小说网站简单了解之后(PS:好多盗版网站真的好丑哦.),去除花里胡哨的功能,保留实用功能. 初步制定了以下几个功能需求,当然,所有需求功能都是我自己设计.自己评审,大不了到时 ...

  9. 关于CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary AS

    1.添加用户"Network Service” 和 “IIS_IUSERS” 读下面目录的读写权限 a) C:\Windows\Temp b) C:\Windows\Microsoft.NE ...

  10. C#在线运行--cmd方法

       此次C#在线运行采用cmd.exe用csc对文件进行编译,然后再运行的思路实现在线运行的效果.不过会生成二个文件(.cs和.exe),可能需要定期清除临时文件夹. 首先利用时间戳生成唯一文件名, ...